[英]How to loop Ranges in VBA?
我是 VBA 中的新手,我有一個問題,即如何在 VBA 中循環范圍,例如: Range("A1:D1").select
到Range("A100:D100").select
或者
Range("A1:D1").select
到Range("D1:G1").select
?
注意:最好避免使用Select
、 Activate
等...
要遍歷每行更改的范圍,請使用For
循環lRow
下面的lRow
:
' loop example per your case
For lRow = 1 To 100
Range("A" & lRow & ":D" & lRow).Select
Next lRow
要循環遍歷每列更改的范圍,請使用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.