I am trying to scan a range for different specific numbers. For every instance where the number is found an action is then performed. However, if one of the specific numbers is not located in the range I get errors. How do I modify my code so that if "9111" isn't found it will start looking for "2990"? There are about 10 different numbers I am searching for.
VBA Code:
Dim SelectCells As Range
Dim xCell As Object
Dim Rng As Range
Dim Ws1 As Worksheet
Set Ws1 = Worksheets("WF")
Set Rng = Ws1.Range("F1:F500")
Set SelectCells = Nothing
For Each xCell In Rng
If xCell.Value = "9111" Then
If SelectCells Is Nothing Then
Set SelectCells = Range(xCell.Address)
Else
Set SelectCells = Union(SelectCells, Range(xCell.Address))
End If
End If
Next
***Do something***
For Each xCell In Rng
If xCell.Value = "2990" Then
If SelectCells Is Nothing Then
Set SelectCells = Range(xCell.Address)
Else
Set SelectCells = Union(SelectCells, Range(xCell.Address))
End If
End If
Next
***Do something***