J
JSnow
I have a workbook w/ many sheets which I need to occassionaly cycle through
to find a policy number. I have written code to exclude sheet "Sheet1" and
search all other sheets. It does not work.
Here is the code:
Sub FindPolicy()
Dim ws As Worksheet
Dim policy As String
policy = Application.InputBox(prompt:="Enter policy number to find", _
Title:="FIND POLICY", Type:=1)
If policy = "False" Then Exit Sub
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
On Error Resume Next
Set pFind = Cells.Find(What:=policy, after:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False)
On Error GoTo 0
If pFind Is Nothing Then
lReply = MsgBox("Policy cannot be found. Try Again", vbYesNo)
If lReply = vbYes Then
Run "FindPolicy"
Else
End
End If
Else
pFind.Select
End If
End If
Next
End Sub
to find a policy number. I have written code to exclude sheet "Sheet1" and
search all other sheets. It does not work.
Here is the code:
Sub FindPolicy()
Dim ws As Worksheet
Dim policy As String
policy = Application.InputBox(prompt:="Enter policy number to find", _
Title:="FIND POLICY", Type:=1)
If policy = "False" Then Exit Sub
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
On Error Resume Next
Set pFind = Cells.Find(What:=policy, after:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False)
On Error GoTo 0
If pFind Is Nothing Then
lReply = MsgBox("Policy cannot be found. Try Again", vbYesNo)
If lReply = vbYes Then
Run "FindPolicy"
Else
End
End If
Else
pFind.Select
End If
End If
Next
End Sub