对于我的一个项目,我试图在VBA中产生一个宏,GOTO语句的目的是重复Do while循环,直到它被强制停止。
每次我尝试运行程序时,应用程序的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
发布于 2014-03-13 07:15:14
把counter =1移到"Jump“之后怎么样?下一次使用for循环。
https://stackoverflow.com/questions/22365732
复制相似问题