Counting Number of cells that have been highlighted following conditional formatting

sthomson

New Member
Joined
Jun 29, 2011
Messages
24
Hi,

I am at my wits end with this. i have searched everywhere but nothing seems to be working for me.

I have a spreadsheet of products that i am looking to purchase for my company.

I have a column for each of the companies that are quoting for these products. I have put in conditional formatting that highlights the cell if its the lowest price in that row.

At the bottom of each column i want to be able to count the number of cells that have been highlighted. this will then show me how many of the 100+ products have the lowest price for each of the companies.

I hope that makes sense and i hope that someone can help me with this.

Thanks for reading my post and i hope to hear from you soon.
 
Conditional Formatting uses a separate way or path to work with colors.
Paste the below UDF into a Standard module
In your worksheet enter

=Countcolors(F2:F108)

Code:
Function CountColors(myRng) As Long
Dim Rng As Range, C As Range
Dim Cnt As Long
Set Rng = myRng
For Each C In Rng
    If C.FormatConditions(1).Interior.ColorIndex = 3 Then  '3 = Red
     Cnt = Cnt + 1
    End If
Next C
CountColors = Cnt
End Function


Jim, you are correct that for a cell .Interior.ColorIndex will only return it's 'base' format colour and not it's actual colour if cf is applied and true.
Similarly, .FormatConditions(1).Interior.ColorIndex will only return the expected cf colour for that cf condition of that cell.

So your code cannot actually detect nor count the applied cf colours.

Here is a link that explains how cf colour can be detected but it is not as simple as we might imagine.
Conditional Formatting Colors
 
Last edited:
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
@snakehips:You are right about that, i was working from the premise of the cells being colored via fill rather than conditional formatting.Silly me :)
 
Upvote 0
Jim, you are correct that for a cell .Interior.ColorIndex will only return it's 'base' format colour and not it's actual colour if cf is applied and true.
Similarly, .FormatConditions(1).Interior.ColorIndex will only return the expected cf colour for that cf condition of that cell.

So your code cannot actually detect nor count the applied cf colours.

Here is a link that explains how cf colour can be detected but it is not as simple as we might imagine.
Conditional Formatting Colors


Snakehips, is there VBA code that would work for this? I was following this string thinking this is exactly what I'm looking for and then it went over to a helper column which wouldn't work for me due to the complexity of all the formulas. I've been searching and searching and haven't found anything but think VBA would be my best option.

Thanks, Bill
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,795
Members
451,589
Latest member
Harold14

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