Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding Find/Replace - When not found 1

Status
Not open for further replies.

MrsTFB

MIS
Oct 3, 2000
307
US
I'm writing a lot of code to go through a LARGE customer file and replace an existing customer number with a new number (I've pasted a snippet below). What I don't know how to do is have it continue going if that number is not found. I don't want it to drop out of the routine, just go to the next Find/Replace block. As below if the W81169 is not found in the worksheet, continue on to the Y37703 without an error message.

Does this make sense? Any help? I'm sure it can be done, I just don't have the knowledge.

Cells.Find(What:="W81169", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Replace What:="W81169", Replacement:="AO0662", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ActiveCell.Font.ColorIndex = 53
Cells.Find(What:="Y37703", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Replace What:="Y37703", Replacement:="AO4595", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ActiveCell.Font.ColorIndex = 53
 
A starting point:
Code:
Set r = Cells.Find(What:="W81169", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
If Not (r Is Nothing) Then
    r.Replace What:="W81169", Replacement:="AO0662", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    r.Font.ColorIndex = 53
End If
Set r = Cells.Find(What:="Y37703", ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That works perfectly. I love this site, Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top