I am a supervisor, I get reports that I need to find all of the agents that work under me and highlight their rows, I have written some VB script that does this however it is very difficult to change as I add or delete someone from my team, I am sure there is a way to do this without specifing each person and doing a macro for each person. Is there a way to have the macro look at a "list" and search for each person and highlight them? This is the VB that I am currently using:
Sub JohnDoe()
For counter = 1 To 20
On Error GoTo MyErrorHandler
Cells.Find(What:="John Doe", 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
Application.Run "PERSONAL.XLS!JaneDoe"
Exit Sub
MyErrorHandler:
If Err.Number = 91 Then
Application.Run "PERSONAL.XLS!JaneDoe"
End If
End Sub
Sub JaneDoe()
For counter = 1 To 20
On Error GoTo MyErrorHandler
Cells.Find(What:="Jane Doe", 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
Application.Run "PERSONAL.XLS!JohnSmith"
Exit Sub
MyErrorHandler:
If Err.Number = 91 Then
Application.Run "PERSONAL.XLS!JohnSmith"
End If
End Sub
Sub JohnSmith()
For counter = 1 To 20
On Error GoTo MyErrorHandler
Cells.Find(What:="John Smith", 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
MsgBox ("Done"
Exit Sub
MyErrorHandler:
If Err.Number = 91 Then
MsgBox ("Done"
End If
End Sub
I have over 50 agents, so you can imagine as I add and delete them it is a real pain in the rump to have to go to each macro and change the names over and over again.
In advance thanks a lot!!!
Sub JohnDoe()
For counter = 1 To 20
On Error GoTo MyErrorHandler
Cells.Find(What:="John Doe", 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
Application.Run "PERSONAL.XLS!JaneDoe"
Exit Sub
MyErrorHandler:
If Err.Number = 91 Then
Application.Run "PERSONAL.XLS!JaneDoe"
End If
End Sub
Sub JaneDoe()
For counter = 1 To 20
On Error GoTo MyErrorHandler
Cells.Find(What:="Jane Doe", 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
Application.Run "PERSONAL.XLS!JohnSmith"
Exit Sub
MyErrorHandler:
If Err.Number = 91 Then
Application.Run "PERSONAL.XLS!JohnSmith"
End If
End Sub
Sub JohnSmith()
For counter = 1 To 20
On Error GoTo MyErrorHandler
Cells.Find(What:="John Smith", 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
MsgBox ("Done"
Exit Sub
MyErrorHandler:
If Err.Number = 91 Then
MsgBox ("Done"
End If
End Sub
I have over 50 agents, so you can imagine as I add and delete them it is a real pain in the rump to have to go to each macro and change the names over and over again.
In advance thanks a lot!!!