Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

STL - Formerly Best Training Solutions Through Learning
TrustPilot
Excellent
Request Callback We will call you back
0207 987 3777 Call for assistance
Your Basket Basket is empty
vba

ResolvedVersion 2003

Seigo has attended:
Excel VBA Intro Intermediate course

VBA

How would you count things by colour or format

RE: VBA

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

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.