Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Finding Cells Filled with a Particular Color.
Written by Allen Wyatt (last updated October 13, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003
Vanita asked if there is a way to select cells containing a specific color. Accomplishing the task is easy if you are using Excel 2003. Just follow these steps:
Figure 1. The Find tab of the Find and Replace dialog box.
Figure 2. The Patterns tab of the Find Format dialog box.
Figure 3. The expanded Find and Replace dialog box.
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.
If you would like to find out other macro-based solutions, you can refer to the following article at the Microsoft Knowledge Base:
http://support.microsoft.com/kb/142122
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2396) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Finding Cells Filled with a Particular Color.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
If you need to know whether a particular value is odd or even, you can use this simple formula. Designed to be used in a ...
Discover MoreDoes your macro need to allow the user to specify a particular file name that should be used by the macro? Here's a quick ...
Discover MoreUnprotecting a single worksheet is relatively easy. Unprotecting a whole lot of worksheets is harder. Here's how you can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-08-07 09:16:59
Aleixa Gan
Allen,
I tried to use your macro to search today's cell and it didn't work.
I have a list of dates (two years ) on one line. I have conditional formatting whereby today's date appears in yellow (vbYellow) (255,255,0),
I want a macro, or a formula in the cell, that puts the cursor on today's date, without having to look visually.
I ran the macro in this list and it showed that there are no cells with that color....
w10 x 64 Excel 2021
Something happens!
Grateful!
Aleixa
2021-03-30 00:10:51
TEDI SAGAL
I have color coded duplicate cells, i would like to sort by color. is there a way to preform this task?
2018-07-09 15:20:30
lukasss21
thanks for the tip. I do however have a question. I want my code to create a range of cells that are colored. Lets say i have A1-A20 cells. All of them have a letter (either A or B) in it, but some cells are white, some yellow. I would like my code to create a range with only yellow cells. Than I would like my code to search for letter A in this range. I have tried to modify your code but im probably doing something wrong: (see Figure 1 below)
I would love to get an answer,
-Lukas
Figure 1.
2018-03-27 17:18:53
Jai
is there a macro we can add to the above code, to only keep the rows which have a cell colored in any of the particular colors?
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments