On Error Loop

mlk11

New Member
Joined
Feb 22, 2017
Messages
9
I want On Error to loop indefinitely if necessary. (On very few occasions it takes 4/5 attempts to force my code to go through, but most times it's fine)

Code:
On Error GoTo StartAgain7StartAgain7:
On Error GoTo StartAgain7
Call extract_details

The on error works the first time around, but if I get a second error message, the error pops up.

I've also tried putting the on error in the extract_details sub, but also experiencing the same issue. I'm doing it this way as I need the code to run again if an error is generated.

Would anyone be able to assist?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
First of all you need to reset it after each error occurs with On Error Goto 0.

Second and more importantly why if you are getting multiple errors aren't you coding to avoid them as using an On Error to avoid multiple errors is really not good practice.
 
Upvote 0
I look at errors as a fire alarm going off saying your house is on fire. It's telling you there is a problem with this code.
And when you say On Error do this your saying yes I know my house is on fire but that's Ok just ignore it.
 
Upvote 0
When you use On Error you can not identify what the error is due to, and you are only ignoring any type of error.


It is better to try to control errors with code.


For example:
If you use a sheet and it does not exist, the easiest thing is:

Code:
Sub test_1()
    On Error GoTo IdontCare
    Sheets("Control").Select
    Range("G5").Value = "Hello"
    
IdontCare:
    MsgBox "An error occurred but I do not know which one"
End Sub

Or you control the error:

Code:
Sub test_2()
    exists = False
    For Each sh In Sheets
        If sh.Name = "Control" Then
            exists = True
        End If
    Next
    '
    If exists Then
        Sheets("Control").Range("G5").Value = "Hello"
    Else
        MsgBox "Sheet does not exists"""
    End If
End Sub

-------------
Explain why you want to continue with error.
You can put your code and we help you identify the problem, control the error with code and allow the code to flow so that you achieve your goal.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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