I have a macro written that searches for a name in a workbook and then highlights the entire row to a different color. This works great when the persons name is in the workbook, however, if the name is not in the workbook I get an error, I need help adding to my macro some sort of IF or IIF statement that will allow the find and highlight to move on if the find command does not find the persons name that is specified. HELP!!!
Below is the VB that I am currently using.
Sub FindandHighlight()
For counter = 1 To 20
Cells.Find(What:="Person One", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Select
Selection.Interior.ColorIndex = 3
ActiveCell.Offset(1, 0).Range("A1"
.Select
Next counter
For counter = 1 To 20
Cells.Find(What:="Person Two", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Select
Selection.Interior.ColorIndex = 3
ActiveCell.Offset(1, 0).Range("A1"
.Select
Next counter
For counter = 1 To 20
Cells.Find(What:="Person Three", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Select
Selection.Interior.ColorIndex = 3
ActiveCell.Offset(1, 0).Range("A1"
.Select
Next counter
End Sub
Below is the VB that I am currently using.
Sub FindandHighlight()
For counter = 1 To 20
Cells.Find(What:="Person One", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Select
Selection.Interior.ColorIndex = 3
ActiveCell.Offset(1, 0).Range("A1"
Next counter
For counter = 1 To 20
Cells.Find(What:="Person Two", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Select
Selection.Interior.ColorIndex = 3
ActiveCell.Offset(1, 0).Range("A1"
Next counter
For counter = 1 To 20
Cells.Find(What:="Person Three", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Select
Selection.Interior.ColorIndex = 3
ActiveCell.Offset(1, 0).Range("A1"
Next counter
End Sub