Sunday, October 26, 2014

Finding Cells Filled with a Particular Color

Finding Cells Filled with a Particular Color

  1. Press Ctrl+F to display the Find tab of the Find and Replace dialog box. (See Figure 1.)
  2. Figure 1. The Find tab of the Find and Replace dialog box.
  3. Make sure there is nothing in the Find What box.
  4. Click Format. (You may need to click Options to see the Format button.) Excel displays the Find Format dialog box.
  5. Make sure the Patterns tab is displayed. (See Figure 2.)
  6. Figure 2. The Patterns tab of the Find Format dialog box.
  7. From the colors available, choose the color you want to find.
  8. Click OK to close the Find Format dialog box.
  9. 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.)
  10. Figure 3. The expanded Find and Replace dialog box.
  11. Click one of the cell addresses in the bottom of the dialog box. Excel selects the cell within the actual worksheet.
  12. Press Ctrl+A. All of the addresses within the dialog box are selected.
  13. Click Close. All the cells of the desired color are selected.
If you are using Excel 97, Excel 2000, or Excel 2002 the only way to select cells of a particular color is to use a macro. Consider the macro shown here:
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  
To use the macro, select a range of cells before running it. The macro then steps through each selected cell and compares its color with whatever color you specify in lColor. If a match is found, then the cell is added to a selection set. When completed, the macro selects only those matching cells, and then exits.

No comments:

Post a Comment