[英]How to loop Ranges in VBA?
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
我是 VBA 中的新手,我有一个问题,即如何在 VBA 中循环范围,例如: Range("A1:D1").select
到Range("A100:D100").select
or或者
Range("A1:D1").select
to Range("D1:G1").select
? Range("A1:D1").select
到Range("D1:G1").select
?
Note : it is better to avoid using Select
, Activate
, etc...注意:最好避免使用Select
、 Activate
等...
To loop through ranges that changes per row, use the For
loop through lRow
below:要遍历每行更改的范围,请使用For
循环lRow
下面的lRow
:
' 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:要循环遍历每列更改的范围,请使用For
循环遍历下面的Col
:
' loop example per your case
For Col = 1 To 4
Range(Cells(1, Col), Cells(1, Col + 3)).Select
Next Col
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.