简体   繁体   中英

extended row selection by n column in Excel VBA

It is confusing me because normally I will use number for column, however, for this case, I have to use letter for column.

For example, T1 and now I would like to extended by n column.

  • n = 10 , then range is T1:T11
  • n = 20 , then range is T1:T22

It is column then I can use .resize, what method I can use instead of resize to get what I would like to?

I'm not sure what you're trying to do. To resize columns, this should work:

Dim rng As Range
Set rng = Sheet1.Range("t1:t11")
rng.Resize(, 10).Select

If you're trying to do rows, this seems to work on my test sheet:

Dim rng As Range
Set rng = Sheet1.Range("t1:t11")
rng.Resize(rng.Rows.Count + 10, 1).Select

A third way I've interpreted your question:

Dim RowCounter As Long
RowCounter = 20
Range("T1:T" & RowCounter + 1).Select

Here's another way:

Dim rng As Range
Dim RowExtend As Long

RowExtend = 20

Set rng = Sheet1.Range("t1")
rng.Resize(rng.Rows.Count + RowExtend, 1).Select

Hopefully one of these four ways gets you close. If not, please clarify your question and I"ll keep hacking away at it.

How about extending the current selection to LEFT ? Ex: current selection is E10:E100 and I would need to extend the selection to the left with 2 columns, to C10:E100 ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM