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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
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.)
 

Forum statistics

Threads
1,136,989
Messages
5,678,975
Members
419,796
Latest member
doctorgresham

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
Top