Hi Mike,
Unfortunately you did not confirm the last thing on my previous post. Are
all the names to be found in the first cell of each of the ranges Players1
and Players2.
Here is what I have assuming the above is correct. It is full of comment so
that you can see what is happening.
If you don't want to 'undo' the colors each time you run the macro because
you want to search more than one then you will see that I have said where to
remove the lines.
You can undo by simply selecting all cells in the worksheet and using the
fill icon on the toolbar and select the appropriate no fill option.
If you need any more from me than I need a quick answer from you because
I'll be unavailable for a few days.
Sub Color_Rows()
Dim rng1 As Range 'For Players1 range
Dim rng2 As Range 'For Players2 range
Dim cellSelect As Variant 'For Selected cell
Dim i As Single 'Used in For/Next loops
'Test if more than one cell selected.
'This must be the first test otherwise a
'VBA code error will occur on next test.
If Selection.Cells.Count > 1 Then
GoTo invalSelect 'Selection was invalid
End If
'Test if selection is a blank cell or
'if selection not in column A.
If Selection = "" Or Selection.Column <> 1 Then
GoTo invalSelect 'Selection was invalid
End If
'Remove any existing interior colors.
'If you don't want to do this every time then the next 2
'lines need to be in a separate procedure.
Sheets("Sheet2").Cells.Interior.ColorIndex = xlColorIndexNone
Sheets("Sheet3").Cells.Interior.ColorIndex = xlColorIndexNone
'Assign ranges to VBA variables
Set rng1 = Sheets("Sheet2").Range("Players1")
Set rng2 = Sheets("Sheet3").Range("Players2")
'Assign Activecell value to a VBA variable
cellSelect = ActiveCell
With rng1
For i = 1 To .Rows.Count 'To number of rows in rng1
If .Cells(i, 1) = cellSelect Then 'Test cells column 1 only
.Cells(i, 1).EntireRow.Interior.ColorIndex = 6
End If
Next i
End With
With rng2
For i = 1 To .Rows.Count 'To number of rows in rng2
If .Cells(i, 1) = cellSelect Then 'Test cells column 1 only
.Cells(i, 1).EntireRow.Interior.ColorIndex = 6
End If
Next i
End With
End 'If get to here then end and do not process InvalSelect code
invalSelect: 'Label for start of invalid selection routine
MsgBox "Invalid selection. Rules for selection are:-" & _
Chr(13) & Chr(13) & "Select one cell only" & _
Chr(13) & "Selection to be in column A only" & _
Chr(13) & "Selection not to be a blank cell" & _
Chr(13) & Chr(13) & "Processing will terminate"
End Sub
Regards,
OssieMac