vba

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

TrustPilot

starstarstarstarstar Excellent

  • Home
  • Courses
  • Promotions
  • Schedule
  • Formats
  • Our Clients

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA

VBA

resolvedResolved · Low Priority · Version 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


 

Excel tip:

Quickly create a list of numbers

The 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.

If you wish to create a list of numbers that increment by one at a time, hold down Ctrl in conjunction with using the fill handle - this should give you a series of numbers (e.g. 1, 2, 3 etc) rather than copying a single number.

View all Excel hints and tips


Server loaded in 0.07 secs.