On Error loop to next 'x'

blacktour

Board Regular
Joined
May 24, 2005
Messages
219
I have a program running and I am having problems with error handling. The program is in a loop, it loops through numbers on a spreadsheet looks up the numbers in a website if the number is there it works flawlessly. If the number isn't there it gives an error.

It is a For x = 5 to 'Max' (variable)

When any kind of error hits I want it to look to the next x so if it is on 15 I want it to skip it and go to 16? Any ideas how to accomplish this?

Thanks,
Mike
 
Okay, you are saying that you want it, in essence, to go to the bottom of the loop (the Next) if it runs into a non-numeric?
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The error actually occurrs when it logs onto the website and tries to look up the value from A5 on the spreadsheet. Then it crashes.

I'd be focussing on what is happening here. I presume logging on isn't a problem.

How are you doing the lookup, i.e. what specific line of code does the search?
 
Upvote 0
Rich (BB code):
Sub exa()
Dim i As Long, a As Long
    
    On Error Resume Next
    For i = 1 To 6
        
        If Not IsNumeric(Cells(i, 1)) Then GoTo Jump
        a = a + Cells(i, 1)
        
        MsgBox "Other code"
        
Jump:
    Next
End Sub

Maybe, but do we need to worry bout an empty cell? If so, add IF NOT Cells(i,1).value = vbNullString
 
Upvote 0
Rich (BB code):
Sub exa()
Dim i As Long, a As Long
    
    On Error Resume Next
    For i = 1 To 6
        
        If Not IsNumeric(Cells(i, 1)) Then GoTo Jump
        a = a + Cells(i, 1)
        
        MsgBox "Other code"
        
Jump:
    Next
End Sub

Maybe, but do we need to worry bout an empty cell? If so, add IF NOT Cells(i,1).value = vbNullString

FIXED!!!! This is exactly what I was looking for. My code when it found the right website it copied that data to an new workbook in excel. I also didn't have it going back to the original workbook so it was picking up the next 'x' on the new workbook which was empty. Thanks so much everyone, you saved me again!!!!!!!
 
Upvote 0
Sorry - take out the On Error Resume Next, that was sloppy of me.
 
Upvote 0
Code:
For i = 1 To 5
    Rem some code

    On Error Goto NextLoop
    Rem possible erroring code
    On Error Goto 0
 
    Rem other code

NextLoop:
    Err.Clear
    On Error Goto 0
Next i
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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