Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Cells in Excel

Status
Not open for further replies.

Edrondol

IS-IT--Management
Feb 20, 2003
63
US
I know this is foolish. I have a spreadsheet that is color coded beyond belief. Because of its complexity, we need to be able to count how many of each color are in the range. I have that one figured out by using the following:

Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long

Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = False Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function


The problem is that we are now using strikethrough characters and need to count those separately. I can't seem to get that one. Anyone see what I can do? I know this is probably an easy one, but my brain hurts.


-Dave

-Dave the Perpetually Confused
 
Sort by Font Colors
If you have color fonts in Col A you could fill Col B with the color values.

in col C formula =COUNTIF(C:C,INDEX(C1,1,1)) and drag down to get counts

Code:
Sub colorval()
  for ii - 1 to (last row)
   Rows(ii).Columns(2)= Rows(ii).Columns(1).Font.Colorindex
  next ii
Endsub




 
I knew that was going to confuse people. I just wanted to include the color stuff so that you could see how I've started. I need to count the cells that have the font strikethrough. I have the colors already. (Sorry!)

-Dave the Perpetually Confused
 
Code:
Rows(ii).Columns(2) = Rows(ii).Columns(1).Font.Strikethrough
 
should have added that font.strikethrough rerurns true/false

but the formula =COUNTIF(C:C,INDEX(C1,1,1)) still works to count all the (trues/falses). Trues have strikethroughs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top