Excel中的“Do Until”循环有什么问题?

时间:2014-01-08 05:28:24

标签: excel excel-vba vba

我正在尝试重复此过程x次,但我不断收到消息“编译错误:无需循环”

这是我的代码

Do Until x > 10
    x = x + 1
    For Each Row In propertytable
    Range("A2,B2,C2,D2,E2").Select
    Range("E2").Activate
    Selection.Copy
    Sheets("Copy to' sheet").Select
    Range("A1").Select
    ActiveSheet.Paste
    Rows("1:1").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Sheets("Property table").Select
    Rows("2:2").Select
    Selection.Delete Shift:=xlUp
    Sheets("Copy to' sheet").Select
Loop   

提前感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:2)

缩进代码会使Next Row的遗漏更加明显。

Do Until x > 10
    x = x + 1
    For Each Row In propertytable
        Range("A2,B2,C2,D2,E2").Select
        Range("E2").Activate
        Selection.Copy
        Sheets("Copy to' sheet").Select
        Range("A1").Select
        ActiveSheet.Paste
        Rows("1:1").Select
        Application.CutCopyMode = False
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Sheets("Property table").Select
        Rows("2:2").Select
        Selection.Delete Shift:=xlUp
        Sheets("Copy to' sheet").Select
    'with indent it's obvious there's something missing
    Next Row
Loop

我认为在添加Next Row命令后,您可能会遇到其他一些编译错误。