Skip or trap errors depending on cell value

derekpegg

Board Regular
Joined
Oct 7, 2005
Messages
145
I want to be able to either trap errors in my code or skip errors using "on error resume next" depending on the value of a cell (0 or 1). I have put the following code in at the beginning of my macro:

Code:
If Sheets("Report Creation").Range("f7") = 1 Then On Error GoTo ErrHandler Else 
On Error Resume Next

But this does not seem to work and always "resumes next" as I guess this comes after the ErrHandler line. Any ideas on how I can do this?

Thanks in advance
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Good morning derekpegg

How about :

Code:
If Sheets("Report Creation").Range("f7") = 1 Then
On Error GoTo 0
Else
On Error Resume Next
End If

HTH

DominicB
 
Upvote 0
Dominic

Code:
If Sheets("Report Creation").Range("f7") = 1 Then
On Error GoTo ErrHandler
Else
On Error Resume Next
End If

I used your code (but replaced with ErrHandler line) above and it seems to work. Funny thing is the code looks more or less same as my original code to me, just a couple of extra line breaks. Sure there's a good reason for it - I'll just keep on learning. Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,215,646
Messages
6,125,999
Members
449,279
Latest member
Faraz5023

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