Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 770
Dipin Samuel Avatar asked Dec 03 '22 20:12

Dipin Samuel


1 Answers

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

Union(Range("N3:N" & LastRow), Range("P3:R" & LastRow)).Select
like image 95
SJR Avatar answered Dec 18 '22 07:12

SJR