Skip to content

Custom functions to get a cell's background color, font color and color code

csxavier edited this page Jul 25, 2020 · 2 revisions

Here you will find a summary of all the functions we've used in this example as well as a couple of new ones that retrieve color codes.

Note: Please remember that all of these formulas will work only if you have added the user-defined function to your Excel workbook as demonstrated earlier in the article.

Functions to count by color:

  • CountCellsByColor(range, color code)- counts cells with the specified background color. In the above example, we used the following formula to count cells by color =CountCellsByColor(F2:F14,A17) where F2:F14 is the selected range and A17 is the cell with the needed background color. You can use all other formulas listed below in a similar way.

  • CountCellsByFontColor(range, color code) - counts cells with the specified font color.

Formulas to sum by color:

  • SumCellsByColor(range, color code) - calculates the sum of cells with a certain background color.
  • SumCellsByFontColor(range, color code) - calculates the sum of cells with a certain font color.

Formulas to get the color code:

  • GetCellFontColor(cell) - returns the color code of the font color of a specified cell.
  • GetCellColor(cell) - returns the color code of the background color of a specified cell.

The formula to get the color code

Well, counting cells based on color and getting the sum of colored cells was pretty easy, wasn't it? Of course if you have that little VBA gem that makes the magic happen : ) But what if you do not color cells manually and rather use conditional formatting.