Count cells based on colour & value(text)

Paul Naylor

Board Regular
Joined
Sep 2, 2016
Messages
99
Office Version
  1. 365
  2. 2003 or older
Platform
  1. Windows
  2. Mobile
  3. Web
Hi running 97 at work. Got vba code to count cells based on colour . Now want to be able to count based on contents ( text - names) and their colour. How do.i do it in both 97 and 2018?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Is this what you want

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]Description[/td][td]Type[/td][td][/td][td]formula in D2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]Cat[/td][td=bgcolor:#FFC5E2]Feline[/td][td]
3​
[/td][td] =CountText(C:C,C2)[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]Dog[/td][td]Canine[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]Mouse[/td][td]Rodent[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]Lion[/td][td=bgcolor:#FFC5E2]Feline[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]Tiger[/td][td=bgcolor:#FFC5E2]Feline[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Other Sheet[/td][/tr][/table]

Goes in STANDARD module
Code:
Function CountText(rng As Range, countWhat As String)
    Application.Volatile
    CountText = WorksheetFunction.CountIf(rng, countWhat)
End Function
 
Upvote 0
Is this what you want

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]Description[/td][td]Type[/td][td][/td][td]formula in D2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]Cat[/td][td=bgcolor:#FFC5E2]Feline[/td][td]
3​
[/td][td] =CountText(C:C,C2)[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]Dog[/td][td]Canine[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]Mouse[/td][td]Rodent[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]Lion[/td][td=bgcolor:#FFC5E2]Feline[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]Tiger[/td][td=bgcolor:#FFC5E2]Feline[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Other Sheet[/td][/tr][/table]

Goes in STANDARD module
Code:
Function CountText(rng As Range, countWhat As String)
    Application.Volatile
    CountText = WorksheetFunction.CountIf(rng, countWhat)
End Function

Thanks for taking time . Not quite what wanted my fault. Column A is list of account numbers which coloured depending upon whether checked ( green checked , yellow unchecked).Column C is list of names of who's checking them. What I want is to count how many a certain colleague has left to check.

Tried your code , presume just need key code at bottom into vba? and for me it's just counting names not cell colour. Sorry include on postage stamp what know about vba.

Heres code using to count cells based on colour:

Function CountCcolor(range_data As Range, criteria As Range) As Long
Dim datax As Range
Dim xcolor As Long
xcolor = criteria.Interior.ColorIndex
For Each datax In range_data
If datax.Interior.ColorIndex = xcolor Then
CountCcolor = CountCcolor + 1
End If
Next datax
End Function

Regards,
Paul
 
Upvote 0
Is this what you want ?

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][th]
F
[/th][th]
G
[/th][th]
H
[/th][th]
I
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]Value[/td][td]??[/td][td]User[/td][td][/td][td][/td][td]RESULTS[/td][td=bgcolor:#FFFF00][/td][td=bgcolor:#00B050][/td][td] Formula in G2 copied down and across[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td=bgcolor:#FFFF00]Acc_001[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td]Jenny[/td][td]
2​
[/td][td]
7​
[/td][td] =CountColorUser($A$2:$A$24,G$1,$C$2:$C$24,$F2)[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td=bgcolor:#FFFF00]Acc_002[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td]Jacob[/td][td]
7​
[/td][td]
0​
[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td=bgcolor:#00B050]Acc_003[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td]Joe[/td][td]
4​
[/td][td]
3​
[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td=bgcolor:#FFFF00]Acc_004[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td=bgcolor:#00B050]Acc_005[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td=bgcolor:#00B050]Acc_006[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td=bgcolor:#FFFF00]Acc_007[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td=bgcolor:#00B050]Acc_008[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td=bgcolor:#00B050]Acc_009[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td=bgcolor:#00B050]Acc_010[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td=bgcolor:#00B050]Acc_011[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td=bgcolor:#FFFF00]Acc_012[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td=bgcolor:#FFFF00]Acc_013[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td=bgcolor:#FFFF00]Acc_014[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
16
[/td][td=bgcolor:#FFFF00]Acc_015[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
17
[/td][td=bgcolor:#FFFF00]Acc_016[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
18
[/td][td=bgcolor:#FFFF00]Acc_017[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
19
[/td][td=bgcolor:#00B050]Acc_018[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
20
[/td][td=bgcolor:#00B050]Acc_019[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
21
[/td][td=bgcolor:#FFFF00]Acc_020[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
22
[/td][td=bgcolor:#00B050]Acc_021[/td][td][/td][td]Jenny[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
23
[/td][td=bgcolor:#FFFF00]Acc_022[/td][td][/td][td]Joe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
24
[/td][td=bgcolor:#FFFF00]Acc_023[/td][td][/td][td]Jacob[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet3[/td][/tr][/table]

Code:
Function CountColorUser(range_data As Range, criteria As Range, range_user As Range, user As Range) As Long
    Dim dataX As Range, Xcolor As Long, c As Long
    Application.Volatile
    Xcolor = criteria.Interior.ColorIndex
    c = range_user.Column - range_data.Column
    For Each dataX In range_data
        If dataX.Interior.ColorIndex = Xcolor And dataX.Offset(, c) = user Then CountColorUser = CountColorUser + 1
    Next dataX
End Function
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,593
Members
452,654
Latest member
mememe101

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