Counting Colored Cells

CheekyMLG

New Member
Joined
Jun 30, 2011
Messages
17
I need to take a certain range and depending on the color have a cell sum the number of cells that are the certain color. I could not find a solution with the functions. Do I have to write VB script? If so any ideas? If I don't need to

Ex. Cells contain color: Olive Green, Accent 3, Lighter 40%

Need a cell to add up how many cells are given this background

I'm new to this so any help would be much appreciated.
 
CheekyMLG,

The reason the function is not working in cell I11, is because you have a rangename CountByColor assigned to cell I11.


To remove the rangename CountByColor:
Click in cell I11
Click on Insert, Name, Define…
In the Names in workbook: box
Click on COUNTBYCOLOR
And click on the Delete button






Excel Workbook
ABCDEFGHIJKLMN
134235234Number Pulled345452Draft Written123213CompleteHere is a small example I can't post the actual one because it's confidential. I need it to calculate the number of blue cells.So there are 6 blue cells so in M10 I would like it to tell me how many blue cells there are.In M11 I would like it to tell me how many OliveGreen Accent 3 lighter 40% cells there are etc.
22342342342155Complete121
323423412Draft Written2341123123Draft Written
412323343435655Draft Written12323Draft Written
545656234323Complete345344
67676878Number Pulled2342343434Number Pulled
77878989Complete2341254545Complete
889090Draft Written2342Number Pulled6456BlueOlive Green
95675678345345Draft Written3453Draft Written
105673434534345345Complete
111Search Color
12
13
14Will need It to cut the number in half because I only need it to count D, F, H. not all 6 columns.
15
16
17
18
19
20
21
22
23
24
25Number Pulled
26Draft Written
27Complete
28
Sheet3
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
CheekyMLG,

Plus, in the VBA Editor, you have a Module4 with just the following with no code between Sub and End Sub) (delete this code):


Code:
Sub COUNTBYCOLOR()

End Sub
 
Upvote 0
After you fix the duplicate name in a Sub and the range name, try this routine.
Code:
Function CountByColor1(CellColor As Range, SumRange As Range) As Long
  ' CountByColor Function
  ' VBA and Macros for Microsoft Excel by Bill Jelen Mr.Excel, Page 84
  ' =CountByColor(J1,A1:G1)
  ' =CountByColor(cell_address_where_a_specific_color_is, range_to_Count)
  Dim myCell As Range
  Dim iCol As Long
  Dim myTotal As Long
  iCol = CellColor.Interior.Color
  myTotal = 0
  For Each myCell In SumRange
    If myCell.Interior.Color = iCol Then
      myTotal = myTotal + 1
    End If
  Next myCell
  CountByColor1 = myTotal
End Function
 
Last edited:
Upvote 0
CheekyMLG,

Plus, in the VBA Editor, you have a Module4 with just the following with no code between Sub and End Sub) (delete this code):


Code:
Sub COUNTBYCOLOR()

End Sub

could you post the workbook fixed via Boxnet so I can see what I did wrong?

I do what you say, but after insert, there is not name....

Thanks btw. I appreciate it more than you can understand
 
Upvote 0
CheekyMLG,

One last thing to delete.

In the VBA Editor, above the Modules you should see a list in Microsoft Excel Objects.

Double click on Sheet3(Sheet3), and in code section to the right (where the cursor is blinking) erase all this duplicate code.
 
Upvote 0
CheekyMLG,

One last thing to delete.

In the VBA Editor, above the Modules you should see a list in Microsoft Excel Objects.

Double click on Sheet3(Sheet3), and in code section to the right (where the cursor is blinking) erase all this duplicate code.

Can you send me an updated one that you did. So I can see...

Also I keep doing what you tell me, but it's not working...Not sure why.

Also If you could extend the range to the whole colored box B1:G10


That would help massively.
Thanks man.
 
Upvote 0
CheekyMLG,


The functions that I posted earlier are not working in your workbook.


The below screenshot is using Kenneth Hobson's slightly different function, and it is working correctly.


Excel Workbook
ABCDEFGHIJKLMN
134235234Number Pulled345452Draft Written123213CompleteHere is a small example I can't post the actual one because it's confidential. I need it to calculate the number of blue cells.So there are 6 blue cells so in M10 I would like it to tell me how many blue cells there are.In M11 I would like it to tell me how many OliveGreen Accent 3 lighter 40% cells there are etc.
22342342342155Complete121
323423412Draft Written2341123123Draft Written
412323343435655Draft Written12323Draft Written
545656234323Complete345344
67676878Number Pulled2342343434Number Pulled
77878989Complete2341254545Complete
889090Draft Written2342Number Pulled6456BlueOlive Green
95675678345345Draft Written3453Draft Written
105673434534345345Complete
111Search Color
12
Sheet3




Copy Ken's function, and put it in an empty Module in the VBA Editor.

Then in cell I11 enter:
=CountByColor1(K11,B1:B2)


Thank you Ken.
 
Upvote 0
CheekyMLG, Kenneth Hobson,


In my archive file Count Sum By Color.xls, all three functions work correctly?????



Excel Workbook
ABCDEFGHIJ
1100.001.00101.00Search Color
22
32Kenneth Hobson
Sheet1
 
Upvote 0
Here is the CountColors.xlsm that I put up for you at box.net. I just made a new file. Of course when I copied your data, I had to delete the named range CountColors.
CountColors.zip
 
Upvote 0
CheekyMLG, Kenneth Hobson,


In my archive file Count Sum By Color.xls, all three functions work correctly?????



Excel Workbook
ABCDEFGHIJ
1100.001.00101.00Search Color
22
32Kenneth Hobson
Sheet1

It works!!!!!


Thank you guys so much!!!! I appreciate the help and the quickness of your responses.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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