I hvae the following loop:
The idea is that when i is incremented beyond the value for which there exists a worksheet named "daily (i)", that the error handler instantiated takes the code out of the loop and on to the label "doneloop".
However, when the line highlighted in red is executed, VBA pops the error "Subscript out of range".
With that "on Error" statement in the code, shouldn't the action be to take the code execution out of the While loop and on to the line labeled "doneloop"?
Mystified!
Please let me know if you can explain what is going on here or how to make it work so that VBA does not throw an error and instead continues execution at the designated label in the code.
Thanks!
VBA Code:
While (True)
On Error GoTo doneloop
EnterWb.Activate
ShtNam = "daily (" & i & ")"
Which = ShtNam
[COLOR=rgb(184, 49, 47)][B]Sheets(ShtNam).Select[/B][/COLOR]
Call Process_Day_Code
' FormSkipDays.Label1 = " Form is Modeless. End of Execution for " & _
' ShtNam & ". Examine for correct data Update. Press OK to proceed, Cancel to end"
' FormSkipDays.Show vbModeless
i = i + 1
Wend
The idea is that when i is incremented beyond the value for which there exists a worksheet named "daily (i)", that the error handler instantiated takes the code out of the loop and on to the label "doneloop".
However, when the line highlighted in red is executed, VBA pops the error "Subscript out of range".
With that "on Error" statement in the code, shouldn't the action be to take the code execution out of the While loop and on to the line labeled "doneloop"?
Mystified!
Please let me know if you can explain what is going on here or how to make it work so that VBA does not throw an error and instead continues execution at the designated label in the code.
Thanks!