Reputation: 77
I am a newbee in VBA, I have a problem that how to how to loop ranges in VBA
for example:
Range("A1:D1").select
to
Range("A100:D100").select
or
Range("A1:D1").select
to Range("D1:G1").select
?
Upvotes: 2
Views: 12264
Reputation: 33672
Note: it is better to avoid using Select
, Activate
, etc...
To loop through ranges that changes per row, use the For
loop through lRow
below:
' loop example per your case
For lRow = 1 To 100
Range("A" & lRow & ":D" & lRow).Select
Next lRow
To loop through ranges that changes per column, use the For
loop through Col
below:
' loop example per your case
For Col = 1 To 4
Range(Cells(1, Col), Cells(1, Col + 3)).Select
Next Col
Upvotes: 3