Dealing with errors

Lavina

Board Regular
Joined
Dec 18, 2018
Messages
75
Hello guys, ive been trying to do some error management with on error go to ErrorList.

My error list looks like this:
ErrorList:
If Err.Number = 9 Then
MsgBox ("Unable to find data, confirm if sheet: " + populatingArray(i, 4) + " is open")
End If

Error 9 is: Subscript out of range

So every time this error pops up, id like to inform the user that the sheet is not open, and to give him a choice to either: close the macro, open the sheet that was missing and retry running.

Since there's a long process that comes beforehand i don't want to restart the whole sub and id like the code to return to the initial position before the error was encountered and try to run again with the correct sheet open, how do i do that?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You can use resume Next in your error handling routine

something like following may do what you want

Code:
On Error GoTo ErrorList






ErrorList:
    If Err.Number = 9 Then
       If MsgBox("Unable to find data, confirm if sheet: " & populatingArray(i, 4) & " is open" & _
       Chr(10) & "Do You Want To Continue?", 36, "Error") = vbYes Then
        Err.Clear
        Resume Next
        End If
    Else
        MsgBox (Error(Err)), 48, "Error"
    End If
End Sub

You can read more about error handling here:https://excelmacromastery.com/vba-error-handling/

Dave
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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