SlinkRN
Well-known Member
- Joined
- Oct 29, 2002
- Messages
- 724
I am trying to work with a loop so that if an error occurs when searching for a name (name is not found in list), it will then skip some of the lines of the loop and continue on further down in the loop. Unfortunately, it works for the first error but then not again. I simplified the loop as much as I could to keep the code here in the post to a minimum. I cannot use Resume Next because if the name is not found I don't want to enter scores anywhere. Where can I put code that will reset the On Error part so it will work again the next time a name isn't found. I searched the forum but I just can't get it to work. Thanks! Slink
VBA Code:
Sub simpleloopwitherrors()
Dim i As Integer
Dim Bowler As String
Dim ans As Integer
Bowler = "Start"
i = 1
Do Until Bowler = ""
Bowler = Sheets("Bowler").Range("A" & i)
Sheets("Scores").Select
Range("A1:A10").Select
On Error GoTo noname
Selection.Find(What:=Bowler, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 2).Value = 100
ActiveCell.Offset(0, 3).Value = 200
ActiveCell.Offset(0, 4).Value = 300
GoTo nextbowler: 'this skips the noname error code
noname:
ans = MsgBox("The name " & Bowler & " does not exist (or is misspelled). Would you like to skip this bowler?", vbYesNo, "Name not found")
If ans = vbYes Then
GoTo nextbowler
Else
Exit Sub
End If
nextbowler:
i = i + 1
Loop
End Sub