Counting Colored Cells from a Conditional Formatting statement

前端 未结 1 632
后悔当初
后悔当初 2021-01-19 04:46

So I\'m revisiting this from yesterday:

Multi-column vlookup conditional formatting

Everything is working as intended with the conditional formatting stateme

相关标签:
1条回答
  • 2021-01-19 05:24

    Unfortunately, there is not a direct way / VBA methods or properties can give the color of the cell which has conditional formatting applied. As you know, your default/manually filled color will be overridden by conditional formatting. When it comes to conditional formatting, a cell can have more than one condition applied which means more than one color is possible for the cell, which is very dynamic.

    cColor= rng.FormatConditions(1).Interior.ColorIndex ' Color of formula 1 if true
    cColor= rng.FormatConditions(2).Interior.ColorIndex ' Color of formula 2 if true
    cColor= rng.FormatConditions(3).Interior.ColorIndex ' Color of formula 3 if true
    

    Also, these format condition objects have priority value set, so they can get overridden over other based on priority. You can run through all conditions applied on a cell and find colors for each formula,

        For i = 1 To rng.FormatConditions.Count
            cColor = rng.FormatConditions(i).Interior.ColorIndex ' Color of formula i
        Next i
    

    But, this gives only the colors assigned to each condition, how to get the current color of a cell on which these conditions are applied. You will have to evaluate the condition manually with the cell value to conclude whether the condition for the cell returns true or false, then get the color for the same.

    Seems to be difficult, isn't it? But, this is better explained with code which may help you get what you want. Please refer to the links below,

    Get Displayed Cell Color (whether from Conditional Formatting or not)

    Conditional Formatting Colors

    Hope that helps.

    0 讨论(0)
提交回复
热议问题