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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
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
 

derekpegg

Board Regular
Joined
Oct 7, 2005
Messages
145
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!
 

Forum statistics

Threads
1,136,309
Messages
5,674,999
Members
419,541
Latest member
freddyboots

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