Counting Colors in Excel Row

rwmill9716

Active Member
Joined
May 20, 2006
Messages
493
Office Version
  1. 2013
Platform
  1. Windows
I use a function (shown in the accompanying image) that identifies the color in Cell (Q3) and then counts the number of times that color appears in each row (column Q). If I color the Cells manually, which I have done here, the function works fine, but if I use a conditional formatting rule to place the color, my function doesn't count it. I would save a lot of work if I could use conditional formatting rules. Is there a change to the function that would count the number of gold cells placed there by a conditional formatting rule?
 

Attachments

  • 220331 Counting Colors.jpg
    220331 Counting Colors.jpg
    116.9 KB · Views: 17

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You cannot check Conditional Formatted cell colors directly, but you can by using a "helper" function. Replace the code you posted with these two functions. I kept the main function's name the same as you named it so your formulas (if you have them on the sheet) should now work.
VBA Code:
Function CountCcolor(Range_Data As Range, Criteria As Range) As Long
  Dim DataX As Range, XColor As Long
  Application.Volatile
  XColor = Criteria.Interior.ColorIndex
  For Each DataX In Range_Data
    If Evaluate("MyHelperFunction(" & DataX.Address & ")") = XColor Then
      CountCcolor = CountCcolor + 1
    End If
  Next
End Function

Private Function MyHelperFunction(ByVal R As Range) As Double
 MyHelperFunction = R.DisplayFormat.Interior.ColorIndex
End Function
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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