color data count

In this workbook I'd like


count  for every color by column

as shown

data can grown  and shrink as needed

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
I have a UDF that counts,sums or averages by coloured cells.

You can copy the code from this example and use in your own workbooks
an Great Tool

Great  Expert

 Thanks !!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this...

Sub CountByColors()
Dim ws As Worksheet
Dim lr As Long, lc As Long, r As Long, c As Long
Dim clrB As Long, clrP As Long, clrG As Long
Dim cntB As Long, cntP As Long, cntG As Long, cntAM As Long, cntPM As Long
Application.ScreenUpdating = False
Set ws = Sheets("DTA")
lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
If lr < 8 Then Exit Sub
lc = ws.Range("A8").End(xlToRight).Column
If lc < 3 Then Exit Sub

ws.Range(ws.Cells(4, 3), ws.Cells(6, lc)).ClearContents

clrB = ws.Range("A4").Interior.Color
clrP = ws.Range("A5").Interior.Color
clrG = ws.Range("A6").Interior.Color
For r = 8 To lr
    If ws.Range("B" & r).Value = "AM" Then
        cntAM = cntAM + 1
    ElseIf ws.Range("B" & r).Value = "PM" Then
        cntPM = cntPM + 1
    End If
Next r
ws.Range("B2").Value = cntPM
ws.Range("B3").Value = cntAM

For c = 3 To lc
    For r = 8 To lr
        If ws.Cells(r, c).Interior.Color = clrB Then
            cntB = cntB + 1
        ElseIf ws.Cells(r, c).Interior.Color = clrP Then
            cntP = cntP + 1
        ElseIf ws.Cells(r, c).Interior.Color = clrG Then
            cntG = cntG + 1
        End If
    Next r
    ws.Cells(4, c) = cntB
    ws.Cells(5, c) = cntP
    ws.Cells(6, c) = cntG
    cntB = 0
    cntP = 0
    cntG = 0
Next c

Application.ScreenUpdating = True
End Sub

Open in new window

In the attached, click the button called "Count By Colors" to run the code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Martin LissOlder than dirtCommented:
I think this is what you asked for. Click the 'Count Hits' button on Sheet1.
in  any ways this   is an  first class work


Roy Cox ,  Subodh Tiwari (Neeraj) , Martin Liss
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
Roy CoxGroup Finance ManagerCommented:
Sorry, I didn't have time last night. I've added the Function for you plus the formulas to count colours in each column.

The advantage of a Function is that it works like an inbuilt Function and will update automatically when a colour changes.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.