The macro below selects a range, searches for 130620, 130618, 133362,130604, and if found, changes any instance of "BLUE" or "ORANGE" to "BLACK;" however, the user noticed that if the cell that contains 1 of those 4 numbers contains ONLY that number, "BLUE" or "ORANGE" are not updated - but if the cell contains any text or numbers along with 1 of those 4 numbers, it works. Can anyone help me tweak this so it will work when any of those 4 numbers are within the range, whether alone or as part of a string?
Thanks!
Code:
Sub UpdateLabels()
Dim fn As Variant, f As Integer
fn = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select One Or More Files To Open", , True)
If TypeName(fn) = "Boolean" Then Exit Sub
For f = 1 To UBound(fn)
Debug.Print "Selected file #" & f & ": " & fn(f)
Workbooks.Open fn(f)
On Error Resume Next
With Range("A40:Z90")
r = .find(130620, LookIn:=xlValues)
s = .find(130618, LookIn:=xlValues)
t = .find(133362, LookIn:=xlValues)
u = .find(130604, LookIn:=xlValues)
If Not r = "" Then .Replace What:="BLUE", Replacement:="BLACK", LookAt:=xlPart
If Not s = "" Then .Replace What:="BLUE", Replacement:="BLACK", LookAt:=xlPart
If Not t = "" Then .Replace What:="BLUE", Replacement:="BLACK", LookAt:=xlPart
If Not u = "" Then .Replace What:="BLUE", Replacement:="BLACK", LookAt:=xlPart
If Not r = "" Then .Replace What:="ORANGE", Replacement:="BLACK", LookAt:=xlPart
If Not s = "" Then .Replace What:="ORANGE", Replacement:="BLACK", LookAt:=xlPart
If Not t = "" Then .Replace What:="ORANGE", Replacement:="BLACK", LookAt:=xlPart
If Not u = "" Then .Replace What:="ORANGE", Replacement:="BLACK", LookAt:=xlPart
If Not r = "" Then .Replace What:="GREEN", Replacement:="BLACK", LookAt:=xlPart
If Not s = "" Then .Replace What:="GREEN", Replacement:="BLACK", LookAt:=xlPart
If Not t = "" Then .Replace What:="GREEN", Replacement:="BLACK", LookAt:=xlPart
If Not u = "" Then .Replace What:="GREEN", Replacement:="BLACK", LookAt:=xlPart
If Not r = "" Then .Replace What:="RED", Replacement:="BLACK", LookAt:=xlPart
If Not s = "" Then .Replace What:="RED", Replacement:="BLACK", LookAt:=xlPart
If Not t = "" Then .Replace What:="RED", Replacement:="BLACK", LookAt:=xlPart
If Not u = "" Then .Replace What:="RED", Replacement:="BLACK", LookAt:=xlPart
End With
ActiveWorkbook.Close savechanges:=True
Next f
MsgBox "Completed", vbInformation
End Sub
Thanks!