Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 无Do错误的循环,但Do存在_Vba_Excel_Loops - Fatal编程技术网

Vba 无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

以下代码给出了一个没有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 = 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

有道理,谢谢!两者之间有什么区别吗?第二个在我看来更好,也更容易阅读。两者之间没有功能上的区别,除了第一个将进入循环,即使列表开始为空;第二个不会。