简体   繁体   中英

Using VBA to select non-adjacent range

I know how to select a range till a calculated last row using vba as such:

Range("P3:R" & LastRow).Select

Is there a way to select non-adjacent column data? For example I want cells from column N to R WITHOUT column O

Tried below, but it ends up selecting O too, I suspect because the " character should encompass the whole thing, but then how do I keep the variable value for last row?

Range("N3:N" & LastRow , "P3:R" & LastRow).Select

Thanks!

你可以使用Union方法,而不是你通常需要选择任何东西......

Union(Range("N3:N" & LastRow), Range("P3:R" & LastRow)).Select

you can use

Range("N3:N" & LastRow & "," & "P3:R" & LastRow).Select

or

Intersect(Range("N:N, P:R"), Rows(3).Resize(LastRow - 3)).Select

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