Count cells in range that contain specific conditional formatted colors

Gregory123987

New Member
Joined
Jun 23, 2020
Messages
33
Office Version
  1. 2016
Platform
  1. Windows
What I need to do is to count the number of conditional highlighted cells in each row (range) for each color. Ultimately, if the color exists in the range, I intend to have a value of 1, else a value of 0. Here is a worksheet with an example of what the result should be for the first 5 rows. It if matters, my version is Excel 2019 Home & Student. I believe the target system for this spreadsheet is Excel 2016.

FYI - I have spent several hours searching the internet and found several possible solutions but they don't seem to work on this spreadsheet, although they do work on their own spreadsheets. I have removed the code from the workbook and the formulas. I am also thinking there is something in THIS workbook that is preventing the formulas from working. However, I am unable to tell what color is in the cells.

FYI - The conditional formatting uses the standard colors red, yellow, orange and blue in the indicated row in this image. Thank you in advance for your help.
Untitled.png



S2F Data Laps 20210831.xlsm
AAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBH
1
2
3
4# Participants per Day Totals
5466676562666776776776645455
6LAPS RUN
7THFSMTWTHFSMTWTHFSMTWTHFSMTWTHFSWhat should appear
9
101235678910121314151617192021222324262728293031
11
1201000
1360604600461110
1441005140503120401111
15405041400615040514040415041111
16505041505051504051506051505etc
1707041705071704071407071704
18030413005150504140601404
193040414004140403130404104
20
Jul
Cell Formulas
RangeFormula
AA5:BA5AA5=COUNT(AA12:AA19)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
BG10Cellcontains a blank value textNO
BF10Cellcontains a blank value textNO
BE10Cellcontains a blank value textNO
BD10Cellcontains a blank value textNO
AA12:BA19Expression=IF(AA12="","",IF(COUNTBLANK($AA12:AA12),IF(COUNT(OFFSET(AA12,,,,MATCH(2,1/($AA12:AA12=""))-COLUMNS($AA12:AA12)))>$J12+COUNT(OFFSET($AA12,,,,MATCH(TRUE,$AA12:AA12="",0))),COUNT(OFFSET(AA12,,,,MATCH(2,1/($AA12:AA12=""))-COLUMNS($AA12:AA12))),""),MOD(IF($J12<10,$J12)+COUNT($AA12:AA12)-1,IF(COLUMNS($AA12:AA12)<10,10,1E+100))+1))=10textNO
AA12:BA19Expression=IF(AA12="","",IF(COUNTBLANK($AA12:AA12),IF(COUNT(OFFSET(AA12,,,,MATCH(2,1/($AA12:AA12=""))-COLUMNS($AA12:AA12)))>$J12+COUNT(OFFSET($AA12,,,,MATCH(TRUE,$AA12:AA12="",0))),COUNT(OFFSET(AA12,,,,MATCH(2,1/($AA12:AA12=""))-COLUMNS($AA12:AA12))),""),MOD(IF($J12<10,$J12)+COUNT($AA12:AA12)-1,IF(COLUMNS($AA12:AA12)<10,10,1E+100))+1))=5textNO
AA12:BA19Expression=IF(AA12="","",IF(COUNTBLANK($AA12:AA12),IF(COUNT(OFFSET(AA12,,,,MATCH(2,1/($AA12:AA12=""))-COLUMNS($AA12:AA12)))>$J12+COUNT(OFFSET($AA12,,,,MATCH(TRUE,$AA12:AA12="",0))),COUNT(OFFSET(AA12,,,,MATCH(2,1/($AA12:AA12=""))-COLUMNS($AA12:AA12))),""),MOD(IF($J12<10,$J12)+COUNT($AA12:AA12)-1,IF(COLUMNS($AA12:AA12)<10,10,1E+100))+1))=3textNO
AA12:BA19Expression=AND(AA12<>"",($J12+COUNT(AA12:$AA12))=1)textNO
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I think DisplayFormat was available in Excel 2016. If so, you can use this technique to write a UDF that counts the Conditional Formatting colors. You'd need to find the color codes of the colors you're looking for.

 
Upvote 0
I was curious enough to write it up:


VBA Code:
Function DFColor(ByVal R As Range, ColorVal As Long) As Double
Dim r1 As Range

    Application.Volatile
    DFColor = 0
    For Each r1 In R
        If Evaluate("Helper(" & r1.Address() & ")") = ColorVal Then DFColor = DFColor + 1
    Next r1
    
End Function


Private Function Helper(ByVal R As Range) As Double
    Helper = R.DisplayFormat.Interior.Color
End Function

Book1 (version 1).xlsb
ABCDEFG
5123453
Sheet18
Cell Formulas
RangeFormula
G5G5=dfcolor(A5:E5,255)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A5:E5Expression=MOD(A5,2)textNO


The color code for the basic "red" color is 255.
 
Upvote 0
Solution
I was curious enough to write it up:


VBA Code:
Function DFColor(ByVal R As Range, ColorVal As Long) As Double
Dim r1 As Range

    Application.Volatile
    DFColor = 0
    For Each r1 In R
        If Evaluate("Helper(" & r1.Address() & ")") = ColorVal Then DFColor = DFColor + 1
    Next r1
    
End Function


Private Function Helper(ByVal R As Range) As Double
    Helper = R.DisplayFormat.Interior.Color
End Function

Book1 (version 1).xlsb
ABCDEFG
5123453
Sheet18
Cell Formulas
RangeFormula
G5G5=dfcolor(A5:E5,255)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A5:E5Expression=MOD(A5,2)textNO


The color code for the basic "red" color is 255.
I tried this and it worked very well. What are the color codes for the basic yellow, orange and blue as indicated in my OP?
 
Upvote 0
You can find out the values by putting them in cells and having VBA tell you. For example, put the orange color in cell A1, then go into the VBA editor and enter this in the Immediate Window (press CTRL+G if you don't see it)...

? Range("A1").Interior.Color

Whatever value it prints is the color value to use for it.
 
Upvote 0
I am trying to get the count of cells conditionally formatted. Range.Interior.Color each have the value of 16777215

Below is the VBA commands and responses
? Range("BD10").Interior.Color
16777215
? Range("BE10").Interior.Color
16777215
? Range("BF10").Interior.Color
16777215
? Range("BG10").Interior.Color
16777215
 
Upvote 0
I tried this and it worked very well. What are the color codes for the basic yellow, orange and blue as indicated in my OP?
You can find out the values by putting them in cells and having VBA tell you. For example, put the orange color in cell A1, then go into the VBA editor and enter this in the Immediate Window (press CTRL+G if you don't see it)...

? Range("A1").Interior.Color

Whatever value it prints is the color value to use for it.

Thank you both, I was able to figure out the other color codes.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top