They don't take into account any implicit formatting, such as that applied through conditional formatting.To make it easy for people to enter data on a worksheet, you can insert a check box control, using the Form Control tools on the Developer Tab. You'll want to keep in mind that these functions (whether you look at the RGB color values or the color index values) examine the explicit formatting of a cell. You could simply skip that step, however, and rely on the value returned by GetFillColor to put together an IF formula, in this manner: Assuming that cell B5 is formatted using one of the colors you expect (red or green), you can plug the index value back into the earlier macros to get the desired results.
The result is the color index value of cell B5 is displayed. Now, in your worksheet, you can use the following: One way you can do this is to use a very simple macro that does nothing but return a color index value:įunction GetFillColor(Rng As Range) As Long In other words, Excel allows you to use different shades of green and red, so you'll want to make sure that the RGB values and color index values used in the macros match those used by the color shades in your cells. Whether you are using the RGB approach or the color index approach, you'll want to check to make sure that the values used in the macros reflect the actual values used for the colors in the cells you are testing. If you prefer to check index colors instead of RGB colors, then the following variation will work:ĮlseIf = 4 Then You could use the function in a cell in this manner: This macro evaluates the RGB values of the colors in a cell, and returns a string based on those values. For instance, the following example returns one of the three words, based on the color in a target cell: The macro can check the color with which a cell is filled and then return a value. The solution, then, is to use a user-defined function, which is (by definition) a macro. The drawback to this approach, of course, is that it doesn't allow you to reference cells other than the one in which the formula is placed. The result is that you will see text based upon the color of the cell in which you place this formula. With this name defined, you can, in any cell, enter the following: In the Refers To box, enter the following, as a single line:.