以下代码给出了一个没有 Do Compile 错误的循环:
Loop
Sheets("Snap").Rows(1).AutoFilter Field:=5, Criteria1:=List
Sheets("Snap").Range("A1").CurrentRegion.Copy _
Destination:=LastCell
Sheets("RAW").Range("A1").End(xlDown).Offset(1, 0) = "+"
Set List = List.Offset(1, 0)
If IsEmpty(List) Then
Exit Do
End If
Do
但是正如你所看到的那样,Do 存在所以我不知道为什么这会给我一个错误。
最佳答案
你的 Do While ... 循环是倒退的。
do while true
Sheets("Snap").Rows(1).AutoFilter Field:=5, Criteria1:=List
Sheets("Snap").Range("A1").CurrentRegion.Copy _
Destination:=LastCell
Sheets("RAW").Range("A1").End(xlDown).Offset(1, 0) = "+"
Set List = List.Offset(1, 0)
If IsEmpty(List) Then
Exit Do
End If
Loop
交替,
do while not IsEmpty(List)
Sheets("Snap").Rows(1).AutoFilter Field:=5, Criteria1:=List
Sheets("Snap").Range("A1").CurrentRegion.Copy _
Destination:=LastCell
Sheets("RAW").Range("A1").End(xlDown).Offset(1, 0) = "+"
Set List = List.Offset(1, 0)
Loop
关于vba - 循环没有 Do 错误但 Do 存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48864881/