EDIT4:更多问题。现在,我被困在第一个Else If语句中,即使它应该循环。出于某种原因,我的代码卡在该行上,它重置我的RowCntr并从AssignCurrentVars开始,在其中循环以便找到第12列具有空值的记录。
Do
TryCount = 0
AssignCurrentVars:
'Restart the browser if too many errors occur.
If TotalFailures = 3 Then
iret = iim1.iimExit
End If
For Each ws In Workbooks("ElecOpsCSD_FollowUp_iMacro.xlsm").Worksheets
ws.Select
If ws.Name <> "Control" And ws.Name <> "OutputArchive" And ws.Name <> "CC&B_Process" Then
ws.Activate
If ThisWorkbook.ActiveSheet.Cells(RowCntr, 1).Value <> "" Then
If ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = "" Then
Do
FieldOrderID = ThisWorkbook.ActiveSheet.Cells(RowCntr, 1).Text
If Len(FieldOrderID) < 3 Then
FieldOrderID = ""
TryCount = TryCount + 1
If TryCount = 3 Then
GoTo IThinkWereDoneHere
End If
End If
Status = ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Text
'User Initiated Stop Point
If QUITTER = True Then
MsgBox ("Process Halted by User")
GoTo IThinkWereDoneHere
End If
'Error Handler
If FieldOrderID = "" Then
TryCount = TryCount + 1
RowCntr = RowCntr + 1
If TryCount = 3 Then
MsgBox ("Encountered records missing Field Order ID. Process Complete.")
GoTo IThinkWereDoneHere
End If
GoTo AssignCurrentVars
End If
'Skip records that have already been processed, even partially.
If Status <> "" Then
RowCntr = RowCntr + 1
GoTo AssignCurrentVars
End If
Loop Until QUITTER = True Or RowCntr = 10000
ElseIf ThisWorkbook.ActiveSheet.Cells(RowCntr, 1).Value <> "" Then
RowCntr = 2
GoTo AssignCurrentVars
ElseIf ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value <> "" Then
End If
End If
Workbooks("ElecOpsCSD_FollowUp_iMacro.xlsm").Activate
Next ws
Loop Until ws.Name = "CC&B_Process"
答案 0 :(得分:1)
切换到
行的下一个工作表Workbooks("ElecOpsCSD_FollowUp_iMacro.xlsm").Activate
Next ws
所以你可能想在那里将rowCounter设置为1(或任何你想要的数字):
Workbooks("ElecOpsCSD_FollowUp_iMacro.xlsm").Activate
rowCounter = 1
Next ws