VBA/counting colored cell per name

Bill900

New Member
Joined
Dec 3, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I wanted to ask you if someone can help me. I am completely new to VBA and tried this code that counts all my new projects set with the orange color and I have another row with names of employees and I want that VBA counts how many new projects (with this color) have each employee.


Code:

Function CountCellColor(CountRange As Range, _
CountColor As Range, _
Optional IM As Variant) As Long
Dim Color As Long
Dim Total As Integer
Dim rCell As Range
Dim BOOL As Boolean

Color = CountColor.Interior.ColorIndex

For Each rCell In CountRange
If rCell.Interior.ColorIndex = Color Then
BOOL = False
If Not IsMissing(IM) Then
If IM = rCell.Offset(0, 1).Text Then BOOL = True
Else
BOOL = True
End If
If BOOL Then Total = Total + 1
End If
Next rCell
CountCellColor = Total
End Function

1. this is counting the total new projects: where Tabelle1 are the new projects with the background color and ColorProject C1 ist the color itself.
=CountCellColor(Tabelle1!$A:$A;ColorProject!$C$1)

2. counting how many new projects have each employee: List C1 is the name of one of the employee; C2 would be the next etc.
=CountCellColor(Tabelle1!$A:$A;ColorProject!$C$1;Lists!$C$1)

I am attaching pictures of my excel . On my excel it is working perfectly but when I go to the work excel, it shows me correct the total number of the new projects but for each employee it shows me ZERO what is wrong.
I dont know where is the problem. Maybe someone can help.

Thank you.
 

Attachments

  • Code counting by name.JPG
    Code counting by name.JPG
    41.4 KB · Views: 13
  • Projects_Employee.JPG
    Projects_Employee.JPG
    40.6 KB · Views: 13
  • ColorProject.JPG
    ColorProject.JPG
    52 KB · Views: 13

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
and now I realised it does not count correctly. As you can see, we have 7 new projects (orange color) and e.g. Mary has zero new projects but it shows two what is wrong. the same for daniel that has one new project and here shows me two.
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,837
Members
449,471
Latest member
lachbee

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