vbaexcelexcel-automation

Selecting distinct columns with dynamic rows


My data have 10+ columns and from that i want to select three columns and further format those three columns, but the no. of rows are not fixed so I'm unable to select all those three columns at once. Here is what I'm trying to do

Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("G2:H" & lastrow, "J2:J" & lastrow).Select

But this is selecting I columns as well. I tried this also

Range("G2:H & lastrow, J2:J" &lastrow).select

But this gave me error as expected.


Solution

  • Intersect(Range("G:H, J:J"), Rows("2:" & lastrow)).Select