每次我尝试使用goto语句重复一个循环时,我的宏都无法编译



对于我的一个项目,我试图在vba中产生一个宏的goto语句的目的是重复循环时,直到被迫停止为止。

每当我尝试运行程序VBA以进行冻结的程序时,似乎没有任何错误都可以暗示为什么会发生这种情况,并且如果有任何修复程序

Sub buses()
    test.Caption = Day
    Dim mytime As String 'intiger showing current time
    mytime = "string" ' testing perpus only
    Dim counter As Integer 'intiger value for counter
    counter = 1 'counter set at 0
    Dim record As Integer 'intiger value for record
    Jump
    Do While counter < 20 'repeat if statment untill counter reaches 20
    counter = counter + 1 ' upon repeating counter has increased by 1
    If mytime = CStr(ThisWorkbook.Sheets("mon A").Range("A" & counter).Value) Then
    'if current time = a time of due to arive bus then
    record = counter 'record value and counter value are the same
        V1F1.Caption = CStr(ThisWorkbook.Sheets(Day).Range("A" & record).Value) 'display record information on screen
        V1F2.Caption = CStr(ThisWorkbook.Sheets(Day).Range("B" & record).Value)
        V1F3.Caption = CStr(ThisWorkbook.Sheets(Day).Range("C" & record).Value)
    record = record + 1
        V2F1.Caption = CStr(ThisWorkbook.Sheets(Day).Range("A" & record).Value) 'display record information on screen
        V2F2.Caption = CStr(ThisWorkbook.Sheets(Day).Range("B" & record).Value)
        V2F3.Caption = CStr(ThisWorkbook.Sheets(Day).Range("C" & record).Value)
    record = record + 1
        V3F1.Caption = CStr(ThisWorkbook.Sheets(Day).Range("A" & record).Value) 'display record information on screen
        V3F2.Caption = CStr(ThisWorkbook.Sheets(Day).Range("B" & record).Value)
        V3F3.Caption = CStr(ThisWorkbook.Sheets(Day).Range("C" & record).Value)
        Exit Do  'break do
    End If 'end if statment
    Application.Wait DateAdd("s", 1, Now) 'wait 1 second
    Loop ' loop as a result of if stament not being executed
    GoTo Jump: 'repeat Do while
End Sub

在"跳跃"之后如何移动Counter = 1。下次使用循环。

最新更新