COUNTIF a specific coloured text

glad_ir

Board Regular
Joined
Nov 22, 2020
Messages
146
Office Version
  1. 2010
Platform
  1. Windows
Hello All,

Any help with this one would be much appreciated please.

Does anybody know if it is possible to count cells containing text of a specific colour? I have a column with a range of text entries that are coloured green, amber and red. The text entries are variable but the shades of green, amber and red are controlled. I would like to separately sum the green, amber and red text entries.

Thank you,
Iain
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I would like to separately sum the green, amber and red text entries.
Do you mean count the green, amber & red text entries?

This would require vba. Is that acceptable?
If so, are the green/amber/red colours applied manually, by conditional formatting, by vba code, some other way?
 
Upvote 0
Do you mean count the green, amber & red text entries?

This would require vba. Is that acceptable?
If so, are the green/amber/red colours applied manually, by conditional formatting, by vba code, some other way?
Hi Peter,

Thank you for the reply. VBA is acceptable. The colours will be applied manually rather than by other means.

Iain
 
Upvote 0
Could you use something like this then? The text colour in D2:D4 is used to find matches for that colour in column B.
In my sample, cell B5 is formatted as Red font but is excluded from the count since there is no text in that cell. Is that what you would want?

Post back if you need help implementing this user-defined function.

VBA Code:
Function CountC(rng As Range, clrcell As Range) As Long
  Dim c As Range
  Dim clr As Long
  
  clr = clrcell.Font.Color
  For Each c In rng
    If c.Font.Color = clr And Len(c.Value) > 0 Then CountC = CountC + 1
  Next c
End Function

glad_ir.xlsm
BCDE
1
2text 1green3
3text 2amber0
4text 3red4
5
6text 5
7text 6
8464
9
10text 9
11text 10
12text 11
13text 12
14text 13
15text 14
Sheet1
Cell Formulas
RangeFormula
E2:E4E2=CountC(B$2:B$15,D2)
 
Upvote 0
Solution
Could you use something like this then? The text colour in D2:D4 is used to find matches for that colour in column B.
In my sample, cell B5 is formatted as Red font but is excluded from the count since there is no text in that cell. Is that what you would want?

Post back if you need help implementing this user-defined function.

VBA Code:
Function CountC(rng As Range, clrcell As Range) As Long
  Dim c As Range
  Dim clr As Long
 
  clr = clrcell.Font.Color
  For Each c In rng
    If c.Font.Color = clr And Len(c.Value) > 0 Then CountC = CountC + 1
  Next c
End Function

glad_ir.xlsm
BCDE
1
2text 1green3
3text 2amber0
4text 3red4
5
6text 5
7text 6
8464
9
10text 9
11text 10
12text 11
13text 12
14text 13
15text 14
Sheet1
Cell Formulas
RangeFormula
E2:E4E2=CountC(B$2:B$15,D2)
Thank you....I will give this a try now and come back to let you know how I get on. Thanks again
 
Upvote 0
Hi, this is perfect. I've only used VBA for macros rather than functions before so a neat learning for me here as well!

Thank you for your help. Have a great xmas!

Iain
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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