Formerly Best Training
© 2024 STL. All Rights Reserved.
All prices offered for business users and exclude VAT. E&OE
2nd Floor, CA House, 1 Northey Street, Limehouse Basin, London, E14 8BT. United Kingdom
Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA
Resolved · Low Priority · Version 2003
Seigo has attended:
Excel VBA Intro Intermediate course
How would you count things by colour or format
Hi Seigo
The following function counts the cells in a range with the same colour background or text depending on the option you set up
Public Function CountByColour(MyRange As Range, _
MyColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
' This function return the number of cells in MyRange with
' a background color, or if OfText is True a font color,
' equal to MyColorIndex.
Dim RangeVar As Range
Application.Volatile True
For Each RangeVar In MyRange.Cells
If OfText = True Then
CountByColour = CountByColour - _
(RangeVar.Font.ColorIndex = MyColorIndex)
Else
CountByColour = CountByColour - _
(RangeVar.Interior.ColorIndex = MyColorIndex)
End If
Next RangeVar
End Function
Hope this helps
Carlos
|
Excel tip:Quickly create a list of numbersThe fill handle in Excel has many uses. If a number is typed into a cell and then the fill handle is used, the number will be copied from one cell to the next. |
We'll call during UK business hours
Server loaded in 0.07 secs.