Forum Discussion

and_rogynous's avatar
and_rogynous
Copper Contributor
Mar 17, 2023

Conditional Formatting Changes Cell Color, Then Claims Cell Is Still Uncolored

I'm using a small VBA function to allow conditional formatting based on cell color. The VBA I'm using for this is:   Function IdentifyColor(CellToTest As Range) 'Returns R + (256 * G) + (65536 * ...
  • HansVogelaar's avatar
    Mar 17, 2023

    and_rogynous 

    CellToTest.Interior.Color ignores conditional formatting, it returns the color as if no conditional formatting rules have been applied. You can use CellToTest.DisplayFormat.Interior.Color to get the color as actually displayed taking conditional formatting into account.

    But I'd do it differently, without any VBA.

    Let's say your data are in B3:N1000.

    Select this range. The active cell in the selection should be in row 3.

     

    On the Home tab of the ribbon, click Conditional Formatting > New Rule...
    Select 'Use a formula to determine which cells to format'.
    Enter the formula

    =MOD(COUNTA(UNIQUE($B$3:$B3))-1,9)=0

    Click Format...
    Activate the Fill tab.
    Set the color to pink.
    Click OK, then click OK again.

     

    Repeat these steps, but with the formula

    =MOD(COUNTA(UNIQUE($B$3:$B3))-1,9)=1

    and with aqua as color.

     

    Etc., with the ninth and last rule using

    =MOD(COUNTA(UNIQUE($B$3:$B3))-1,9)=8

Resources