Count cells based on colour & value(text)

Paul Naylor

Board Regular
Joined
Sep 2, 2016
Messages
98
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 is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Is this what you want

Excel 2016 (Windows) 32 bit
B
C
D
E
1
DescriptionTypeformula in D2
2
CatFeline
3​
=CountText(C:C,C2)
3
DogCanine
4
MouseRodent
5
LionFeline
6
TigerFeline
7
Sheet: Other Sheet

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
B
C
D
E
1
DescriptionTypeformula in D2
2
CatFeline
3​
=CountText(C:C,C2)
3
DogCanine
4
MouseRodent
5
LionFeline
6
TigerFeline
7
Sheet: Other Sheet

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
A
B
C
D
E
F
G
H
I
1
Value??UserRESULTS Formula in G2 copied down and across
2
Acc_001JennyJenny
2​
7​
=CountColorUser($A$2:$A$24,G$1,$C$2:$C$24,$F2)
3
Acc_002JennyJacob
7​
0​
4
Acc_003JennyJoe
4​
3​
5
Acc_004Jacob
6
Acc_005Joe
7
Acc_006Jenny
8
Acc_007Jacob
9
Acc_008Jenny
10
Acc_009Joe
11
Acc_010Joe
12
Acc_011Jenny
13
Acc_012Jacob
14
Acc_013Joe
15
Acc_014Jacob
16
Acc_015Jacob
17
Acc_016Joe
18
Acc_017Jacob
19
Acc_018Jenny
20
Acc_019Jenny
21
Acc_020Joe
22
Acc_021Jenny
23
Acc_022Joe
24
Acc_023Jacob
Sheet: Sheet3

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,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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