Finding Cells Filled with a Particular Color
- Press Ctrl+F to display the Find tab of the Find and Replace dialog box. (See Figure 1.)
- Make sure there is nothing in the Find What box.
- Click Format. (You may need to click Options to see the Format button.) Excel displays the Find Format dialog box.
- Make sure the Patterns tab is displayed. (See Figure 2.)
- From the colors available, choose the color you want to find.
- Click OK to close the Find Format dialog box.
- Click Find All. The Find and Replace dialog box expands to show the addresses of all the cells formatted with the color you specified in step 5. (See Figure 3.)
- Click one of the cell addresses in the bottom of the dialog box. Excel selects the cell within the actual worksheet.
- Press Ctrl+A. All of the addresses within the dialog box are selected.
- Click Close. All the cells of the desired color are selected.
Sub SelectColoredCells()
Dim rCell As Range
Dim lColor As Long
Dim rColored As Range
'Select the color by name (8 possible)
'vbBlack, vbBlue, vbGreen, vbCyan,
'vbRed, vbMagenta, vbYellow, vbWhite
lColor = vbBlue
'If you prefer, you can use the RGB function
'to specify a color
'lColor = RGB(0, 0, 255)
Set rColored = Nothing
For Each rCell In Selection
If rCell.Interior.Color = lColor Then
If rColored Is Nothing Then
Set rColored = rCell
Else
Set rColored = Union(rColored, rCell)
End If
End If
Next
If rColored Is Nothing Then
MsgBox "No cells match the color"
Else
rColored.Select
MsgBox "Selected cells match the color:" & _
vbCrLf & rColored.Address
End If
Set rCell = Nothing
Set rColored = Nothing
End Sub