Using VBA to select non-adjacent range
15,601
Solution 1
You could use the Union method, not that you usually need to Select anything...
Union(Range("N3:N" & LastRow), Range("P3:R" & LastRow)).Select
Solution 2
you can use
Range("N3:N" & LastRow & "," & "P3:R" & LastRow).Select
or
Intersect(Range("N:N, P:R"), Rows(3).Resize(LastRow - 3)).Select
Author by
Dipin Samuel
Updated on June 23, 2022Comments
-
Dipin Samuel almost 2 years
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!
-
SJR about 6 yearsGood spot, I hadn't noticed the misplaced comma. You could do
Range("N3:N" & LastRow & ",P3:R" & LastRow).Select
-
DisplayName about 6 years@SJR, True. But I left that comma alone just to "mark" its proper place