Here is a short script that I am having a problem with.
User must input PO number. If PO not found ON ERROR clause works first time. If user re-enters valid PO, no problem. However if user enters another PO that can't be found, then I get error: Run Time error 91: Object variable or with block variable not set.
Why would it capture the first error but not consecutive ones ?
Here's the script:
Sub FindPO()
Dim POSEARCH
POSEARCH = InputBox("Enter PO number to find.")
If POSEARCH = "" Then Exit Sub
Restart:
On Error GoTo POnotFound
Columns("F:F").Select
Selection.Find(What:=POSEARCHNEW, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Exit Sub
POnotFound:
POSEARCH = InputBox("PO number: " & POSEARCH & " was not found. Please enter valid PO number !")
GoTo Restart
End Sub
Thanks for any suggestion
User must input PO number. If PO not found ON ERROR clause works first time. If user re-enters valid PO, no problem. However if user enters another PO that can't be found, then I get error: Run Time error 91: Object variable or with block variable not set.
Why would it capture the first error but not consecutive ones ?
Here's the script:
Sub FindPO()
Dim POSEARCH
POSEARCH = InputBox("Enter PO number to find.")
If POSEARCH = "" Then Exit Sub
Restart:
On Error GoTo POnotFound
Columns("F:F").Select
Selection.Find(What:=POSEARCHNEW, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Exit Sub
POnotFound:
POSEARCH = InputBox("PO number: " & POSEARCH & " was not found. Please enter valid PO number !")
GoTo Restart
End Sub
Thanks for any suggestion