Error Handling - Runtime Error 1004

leeksleeks

Board Regular
Joined
Oct 31, 2013
Messages
96
Hi,

I am wanting to use error handling in some code i have written but am unsure of how to do so. Basically I am importing webpages into excel using the unique numbers associated at the end of the webaddress. When it is trying to import a webpage with a number that doesn't exist I get Run-time error '1004' and the message The internet site reports that the item you requested could not be found. In the code it highlights .Refresh BackgroundQuery:=False.

Basically what I want is an error handler code that when a Runtime 1004 error occurs it does the following:

Application.DisplayAlerts = False
Sheets("Scorecard").Delete
Sheets("Comparison").Delete
Application.DisplayAlerts = True

Next i

Any help you can provide will be greatly appreciated.

Cheers
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
have you tried:
Put this at the top, below your dim

On Error Goto ErrHandler:


Then this at the bottom
exit sub
ErrHandler:
Application.DisplayAlerts = False
Sheets("Scorecard").Delete
Sheets("Comparison").Delete
Application.DisplayAlerts = True
resume next
end sub
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,621
Members
449,109
Latest member
Sebas8956

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