ERROR HANDLING

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

I seem to have allot of trouble with error handling.

Could someone please help/explain

lets say i have a loop that returns an error with that loop, but if you keep waiting it isnt an error any more.

something like the below.

But the below example will only go to the errh: once, why does it not continue to loop?

VBA Code:
retry:

for a = 1 to 10
on error goto errh
  'get info sometimes throws an error but if you wait a second or 2 it will eventually be ok
next a

errh:
application.wait(now + timevalue("00:00:02"))
goto retry

Thanks dave
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,
try this update to your code & see if does what you want

VBA Code:
Sub Squidd()

    On Error GoTo errh
    For a = 1 To 10
    
      'get info sometimes throws an error but if you wait a second or 2 it will eventually be ok
    
retry:
    Next a
    
errh:
    If Err <> 0 Then
        Application.Wait (Now + TimeValue("00:00:02"))
        Resume retry
    End If

End Sub

Dave
 
Upvote 0
Solution
Hi Dave.

That’s great. And I understand how it works.

I haven’t yet tried it in my actual code. But just run a little test and was able to see it getting the error every time.

Very many Thanks. It was driving me crazy.

Dave.
 
Upvote 0
Dave answered your direct question; but, as an aside, if you're having to wait because you're waiting for a query to refresh, you might also consider using Application.CalculateUntilAsyncQueriesDone. That might eliminate the need for the loop/error checking entirely.
 
Upvote 0
Thanks oaktree

Appreciate the suggestion.

The error is as a result data not being available on a webpage.

Although I am waiting for the element to be available. Sometimes it just throws an error randomly. Like 1-2 in 1000 in the loop. But obviously 1 error is enough to bring the code to a stop. Lol.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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