Vba 无Do错误的循环,但Do存在
以下代码给出了一个没有Do编译错误的循环:Vba 无Do错误的循环,但Do存在,vba,excel,loops,Vba,Excel,Loops,以下代码给出了一个没有Do编译错误的循环: 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 = L
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同时。。。循环是反向的
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
有道理,谢谢!两者之间有什么区别吗?第二个在我看来更好,也更容易阅读。两者之间没有功能上的区别,除了第一个将进入循环,即使列表开始为空;第二个不会。