VBA to updae count of colored cells based on value in another column/cell

Prince27

New Member
Joined
Nov 24, 2012
Messages
41
Hello Experts,

Looking for a VB code for the below scenario:

I have 2 sheets : 1 is Summary and another is Suppliers

In Suppliers sheet I have columns like Team Name & Due Date(with colors) as shown in the images.

I want count of colored cells based on a Particular Team Names into the summary sheet:

Summary sheet

Color AmberColor YellowColor Green
Team A11
Team XYZ11
Team DD121
 

Attachments

  • Summary Sheet.JPG
    Summary Sheet.JPG
    18.8 KB · Views: 8
  • Suppliers Sheet.JPG
    Suppliers Sheet.JPG
    32.3 KB · Views: 6
  • Summary Sheet.JPG
    Summary Sheet.JPG
    18.8 KB · Views: 5
  • Suppliers Sheet.JPG
    Suppliers Sheet.JPG
    32.3 KB · Views: 3

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
This is a bit tricky (in my opinion). I created a Named Range which uses Get.Cell (only usable in Named Ranges).

1598888213263.png


Then found the colors and put them in the D column (fill down the simple formula). Then, compared them to the E column (which I manually colored and referenced the colors uniquely shown in column D.
Hope that at least gives you a start.

Book2
CDE
1Due DateCount
28/15/202062
38/15/202063
49/1/2020241
59/1/202024
69/1/202024
710/31/202040
Sheet1
Cell Formulas
RangeFormula
E2E2=COUNTIF($D$2:$D$7,6)
E3E3=COUNTIF($D$2:$D$7,24)
E4E4=COUNTIF($D$2:$D$7,40)
D2:D7D2=MyColors
 
Upvote 0
Here's a function that'll count without using the D column.

Code:
Function GetColorCount(CountRange As Range, CountColor As Range)
Dim CountColorValue As Integer
Dim TotalCount As Integer
CountColorValue = CountColor.Interior.ColorIndex
Set rCell = CountRange
For Each rCell In CountRange
  If rCell.Interior.ColorIndex = CountColorValue Then
    TotalCount = TotalCount + 1
  End If
Next rCell
GetColorCount = TotalCount
End Function

F2 filled down; uses E column:

Code:
=GetColorCount($C$2:$C$7,E2)
 
Upvote 0
Thank for your quickresponse.

Actually i already have code (above) get color function.

But in my scenario i need get color function to be used in combination with another column ( count of color with multiple criteria on multiple columns ) text + color combination.

Appreciate any help on the same
 
Upvote 0
Doesn't GetColorCount do what you want? It counts the number of times a particular background color is found in a range.
Unless I missed it, you didn't specify other criteria.

Do you want to know, for example, now many times DD is in the Yellow?
 
Last edited:
Upvote 0
If the teams are in B and the dates with color backgrounds are in C, and color numbers are in D, maybe you want this:

Code:
=COUNTIFS($D$2:$D$7,D2,$B$2:$B$7,B2)
 
Upvote 0
Nopes, the above condition is for multiple criteria with text and text or text and number or number and number. (I mean more than 1 value or criteria)

Even my requirement is multiple criteria but combination of text and cell color

For example, in Column A there are 10 rows/cells named as Team A, Team B and so on and Column B has the 10 rows/cells filled with different colors (say red, blue , yellow)

i need a formula or VB code to get count of each color based on the different teams given in column A
 
Upvote 0
Book2
BCDE
1TeamDue DateCount
2Team A8/15/202061
3Team B8/15/202061
4Team C9/1/2020242
5Team D9/1/2020241
6Team C9/1/2020242
7Team A10/31/2020401
Sheet1
Cell Formulas
RangeFormula
D2:D7D2=MyColors
E2:E7E2=COUNTIFS($D$2:$D$7,D2,$B$2:$B$7,B2)


I thought this looks at the D column (color) and also the B column (Team) and counts how many are, for example, TeamA and Yellow, etc...
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,495
Members
449,088
Latest member
Melvetica

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