The following macro works great... except when I add more terms to the array. In all, I have about 1000+ terms. Every single time I try to add in the rest, I get an error. Code follows:
Option Explicit
Sub BPO()
Dim TargetList
TargetList = Array("ABRB026", "ABRB026A", "ABRB026AA", "ABRB027")
'Store the active cell in order to return here
Dim ActualCel As Range
Set ActualCel = ActiveCell
Dim cel As Range, Er As Boolean
Dim i As Long
For i = 0 To UBound(TargetList)
On Error GoTo ErrorHandler
'Verify first cell in worksheet
Cells(1, 1).Activate
If UCase(ActiveCell) = UCase(TargetList(i)) Then
ActiveCell.Interior.Color = vbGreen
End If
Er = False
Set cel = Nothing
Do While Not Er
Set cel = Cells.Find(What:=TargetList(i), After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
cel.Activate 'Here an error occured if the text is not found
ActiveCell.Interior.Color = vbGreen
Set cel = Cells.FindNext(After:=ActiveCell)
Er = (cel.Interior.Color = vbGreen) 'If a previous cell is founded again Er=True
Loop
NextI:
Next i
Ex:
MsgBox ("Who's awesome? You're awesome.")
Exit Sub
ErrorHandler:
If i = UBound(TargetList) Then
Resume Ex
Else
Resume NextI
End If
End Sub
Bookmarks