You are here:

Excel/Conditional Formatting


QUESTION: I have cell values in a column with different font colors, which have been determined by conditional formatting. However when i attempt to total the values by font color using a macro, it will not recognize the new font color. Can you help please ?

ANSWER: Chris,

VBA can not see the font color (or cell color) produced by conditional formatting.  The best way is to sum using the condition that the conditional formatting uses to determine the color.

Sorry - but that is the way it is.  

Tom Ogilvy

---------- FOLLOW-UP ----------

QUESTION: Not sure how to do that, given that there are values with different font color also in the column


If you have some cells that have a red font color manually set and you have some cells that have a red font color based on conditional formatting with a rule of =A1>5  in the range from A1 to A100 then you could loop through them  

note: the rule =A1>5 is the relative formula for cell A1.

tot = 0
for each cell in Range("A1:A100")
  if cell.font.colorindex = 3 or cell.value > 5 and isnumeric(cell) then
     tot = tot + cell.value
  end if
Msgbox "Sum of red font cells is :" & tot

Hopefully that illustrates what I am talking about.

Tom Ogilvy


About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 All rights reserved.