Error Handeling in a Loop

skadiet

New Member
Joined
Aug 31, 2006
Messages
3
I believe that I am doing something wrong in my error handeling. For some reason, the program catches the error on the first time through the loop but not the second time. Any ideas why this would be the case?

For i = 1 To 10

loopTime:

On Error GoTo theError

<code>

theNumber = MsgBox("There is no error", vbCritical, "Check")

Next i
Exit Sub

theError:

theNumber = MsgBox("There was an error", vbCritical, "Check")
i = i + 1 'Is this necessary?
GoTo loopTime

end sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello skadiet, welcome to the board.
There is no error to catch in your test code. It's just showing the error message 10
times because it's being told to. I ran it a few times with the same results each time.
Are you getting different results?

(And no, the i = i + 1 is not necessary for this.)
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top