![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 5
|
I have a worksheet with two colored cells. Some are Blue and some are red. is it possible to count the red cells.
These cells are "empty" they are only colored. Sorry my English isn't that good. Hope you know what I mean |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi. Here is a sample I made before.
[ This Message was edited by: Colo on 2002-04-26 00:10 ] |
|
|
|
|
|
#3 | |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
This procedure will count your red cells and place the number in cell A1... Quote:
[ This Message was edited by: TsTom on 2002-04-26 00:14 ] |
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
If you want only red(Index=3) then try this code.
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Sorry Tom.
Almost my reply Is the same as yours. |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
No apology neccesary...
Thanks for the sample code. I will use it! I sent you a message a few minutes ago. Did you read it??? Thanks, Tom |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Here are a couple of UDF that you may
want to use in your worksheet. OPTION1: Counts a User selected range with the colour code you input. eg =CountColorCode(C5:C12,3) Counts the Reds in c5:c15 Function CountColorCode(Range As Range, CCode As Double) As Double Dim YourDataRange As Range Dim kount As Double Dim cell As Range Application.Volatile Set YourDataRange = Intersect(Range.Parent.UsedRange, Range) kount = 0 For Each cell In YourDataRange If cell.Interior.ColorIndex = CCode Then kount = kount + 1 Next cell CountColorCode = kount End Function OPTION2: Counts the range of colours based on the colour code of Range B13 =CountByColor(D1:D13,$B$13) Function CountByColor(InputRange As Range, ColorRange As Range) As Double Dim cl As Range, TempCount As Double, ColorIndex As Integer Application.Volatile ColorIndex = ColorRange.Cells(1, 1).Font.ColorIndex TempCount = 0 On Error Resume Next For Each cl In InputRange.Cells If cl.Value <> "" And cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount + 1 Next cl On Error GoTo 0 Set cl = Nothing CountByColor = TempCount End Function Post if unsure.....Note to get a list of colour codes have a look @ Colos Code. |
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi Tom! I've read it and replied.
Thanks, |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|