Error 91 on Second Error
Hi,
Not very good with error trapping and struggling with a macro that basically
seach tries to find a match within a series of cell's (using selection .find)
all works fine if there is a match, and the first time there is not a match.
But if there is a second no match i get an error 91. Do I need to clear/reset
the error after each occurence ? I have tried but with no success :
Please see relevant section of code :
'1st Search
searchval = 1
pasterow = 2
On Error GoTo line5
Sheets(2).Select
Columns("A:E").Select
Selection.Find(What:=fap, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ddrow = ActiveCell.Row
ddcol = ActiveCell.Column
For ddrow = ddrow To 25
Sheets(2).Select
If Cells(ddrow, ddcol).Value fap Then
ddrow = 25
End If
If Cells(ddrow, ddcol).Value = fap Then
If ddcol = 1 Then
role = Cells(ddrow, 1).Value
rolecount = Cells(ddrow, 2).Value
End If
If ddcol = 4 Then
role = Cells(ddrow, 4).Value
rolecount = Cells(ddrow, 5).Value
End If
Sheets(sh).Select
Cells(pasterow, 1).Value = role
Cells(pasterow, 2).Value = rolecount
pasterow = pasterow + 1
End If
Next ddrow
'2nd search
line3:
searchval = 2
pasterow = 2
On Err GoTo line5
Sheets(3).Select
Columns("A:E").Select
Selection.Find(What:=fap, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
eerow = ActiveCell.Row
ddcol = ActiveCell.Column
For eerow = eerow To 25
Sheets(3).Select
If Cells(eerow, ddcol).Value fap Then
eerow = 25
End If
If Cells(eerow, ddcol).Value = fap Then
If ddcol = 1 Then
role = Cells(eerow, 1).Value
rolecount = Cells(eerow, 2).Value
End If
If ddcol = 4 Then
role = Cells(eerow, 4).Value
rolecount = Cells(eerow, 5).Value
End If
Sheets(sh).Select
Cells(pasterow, 3).Value = role
Cells(pasterow, 4).Value = rolecount
pasterow = pasterow + 1
End If
Next eerow
line4:
selrow = selrow + 1
' Next b
Next a
line5:
If searchval = 1 Then
GoTo line3
Err.Clear
error.Clear
End If
If searchval = 2 Then
GoTo line4
Err.Clear
error.Clear
End If
line1:
End Sub
|