View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
SteveK SteveK is offline
external usenet poster
 
Posts: 9
Default Suggestion for a macro?

Dave,
I got all the integers relating to the specific color, but I don't know
how to incorporate this into the macro. I tried keeping it simple and only
doing one column and counting only one color, but I don't know how to start
the macro to see if it works (can't just click run and select the macro).
I'm guessing that it will run automatically once I figure out how to do get
it to work. I tried one of the macros from the site below and this is what I
have come up with so far. Check it out:

Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function returns the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True 'not exactly sure what this is for
InRange = Range(Cells(h, 5), Cells(h, 55)) 'Range to look for the cells
WhatColorIndex = 3
Rng = Cells(h, 67) 'I think this is the resulting cell?

For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
'Thinking about deleting the If function because it doesnt apply
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function


"Dave F" wrote:

Well the first question is: did you follow the links at ozgrid.com explaining
the colorindex and how that figures into the macro? Some info on colorindex
he http://www.cpearson.com/excel/colors.htm

Basically, the color of the cells you want to count has a number associated
with it; that number (the color index of the cell shading) needs to be
specified.

Dave


--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.