Error handling part way though code

S

Sliman

I have a code that refresh data. Sometime's no data is retrived and
code stops.
What is best way to handel this error. I have following but am sure
there must be a better way to do it as have a lot of error handeling
to add.


'Update Firmorders
On Error GoTo 1
Sheets("Firm orders on RF").Visible = True
Sheets("Firm orders on RF").Select
Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Firm orders on RF").Visible = False
1 Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Sheets("Firm orders on RF").Visible = False
GoTo 2

2 UserForm1.Label4.Caption = "Step 3 in progress"
UserForm1.Repaint

'Update Firm orders not on RF
On Error GoTo 3
Sheets("Firm orders not on RF").Visible = True
Sheets("Firm orders not on RF").Select
Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Firm orders not on RF").Visible = False
3 Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Sheets("Firm orders not on RF").Visible = False
GoTo 4

4 UserForm1.Label4.Caption = "Step 4 in progress"
UserForm1.Repaint

Thanks for any help
Simon
 
G

Gary Keramidas

don't know about the the error, but this may simplify the clearing of the cells.

Set rng = Range("A3")
Range(Range(rng, rng.End(xlToRight)), Range(rng, rng.End(xlDown))).ClearContents

instead of:
Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top