excluding condtinally formatted cells from calculation based on color and font with vba


New Member
Mar 22, 2015
I have created the following function to calculate the sumproduct of two ranges of cells, but only for cell pairs which do not share a cell shade or font color which matches that of another specified cell. It works fine for cells which I have manually formatted the cell shade and font color. However, it seems to fail for cells which have been conditionally formatted. As far as I can tell, it is not even able to recognize that two conditionally formatted cells have a certain shade and font color.

Is there any way to get around this? Or otherwise, is there another way to include/exclude cells from calculation based on their shade and font color?

Function SUMPRODEXCOLOR(rng_one As Range, rng_two As Range, Optional shade_range As Range, Optional text_range As Range)
Dim cSumProd As Double
cSumProd = 0
Dim shadeIndex As Integer
Dim fontIndex As Integer

shadeIndex = shade_range.Interior.ColorIndex
fontIndex = text_range.Font.ColorIndex

For i = 1 To rng_one.Width

If rng_one.Cells(1, i).Interior.ColorIndex <> shadeIndex And rng_one.Cells(1, i).Font.ColorIndex <> fontIndex _
And rng_two.Cells(1, i).Interior.ColorIndex <> shadeIndex And rng_two.Cells(1, i).Font.ColorIndex <> fontIndex Then

cSumProd = cSumProd + rng_one.Cells(1, i) * rng_two.Cells(1, i)

End If



End Function


Well-known Member
Jan 19, 2006
I don't think there is an easy way to check the conditional formatting, it's probably easier just to build the same conditional formula into your function.

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...