2

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Digvijay
  • 406
  • 3
  • 12

1 Answers1

1
Intersect(Range("G:H, J:J"), Rows("2:" & lastrow)).Select
user3598756
  • 28,893
  • 4
  • 18
  • 28
  • @Digvijay, did you get through it? – user3598756 Apr 04 '17 at 06:33
  • 1
    Yes thanks it is selecting those columns, but there is some error with how further formatting happen using intersect to select. I'm converting these selected columns to number format Using `with selection .numberformat = "0"` `.value = .value` when I'm selecting columns normally it's working fine, but using intersect creates `#NA` entries. – Digvijay Apr 04 '17 at 06:43
  • not contiguous cells must be handled differently than contiguous ones. but don't make your question a "chamaleon" one by changing it with _new_ issues as soon as _original_ ones get solved. Since I solved the _original_ selection issue you may want to mark answer as accepted. while for _new_ ones you should post a _new_ question. thank you – user3598756 Apr 04 '17 at 07:15
  • that was not my intention, I thought that this is what I should do i.e update the question here itself. I'll post a new question. – Digvijay Apr 04 '17 at 07:20