Dipin Samuel
Dipin Samuel

Reputation: 71

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!

Upvotes: 7

Views: 23286

Answers (2)

DisplayName
DisplayName

Reputation: 13386

you can use

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

or

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

Upvotes: 8

SJR
SJR

Reputation: 23081

You could use the Union method, not that you usually need to Select anything...

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

Upvotes: 16

Related Questions