Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft Excel > Functions User Defined > COUNTFORMAT< Previous | Next > 

 

COUNTFORMAT(rgeValues, rgeExampleCell [,bBackGround] [,bText])

 
 

Returns the number of cells that have a particular format.

 

 
rgeValuesThe range of values.
rgeExampleCellThe cell whose format you want to match.
bBackGroundWhether you want to check the background formatting.
bTextWhether you want to check the text formatting.
 

 

REMARKS

 
 
  • This function will not update automatically every time a cell format changes although pressing F9 will work.

     

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    Option Explicit

    Public Function COUNTFORMAT(ByVal rgeValues As Range, _
                                ByVal rgeExampleCell As Range, _
                       Optional ByVal bBackGround As Boolean = True, _
                       Optional ByVal bText As Boolean = False) As Integer

    Dim objCell As Range
    Dim itotalcells As Integer

       Call Application.Volatile(True)

       itotalcells = 0
       If bBackGround = True Then
          For Each objCell In rgeValues
             If objCell.Interior.ColorIndex = rgeExampleCell.Interior.ColorIndex Then
                itotalcells = itotalcells + 1
             End If
          Next objCell
       End If

       If bText = True Then
          For Each objCell In rgeValues
             If objCell.Font.ColorIndex = rgeExampleCell.Font.ColorIndex Then
                itotalcells = itotalcells + 1
             End If
          Next objCell
       End If
       
       COUNTFORMAT = itotalcells
    End Function
       

     

    Example

     
       

     Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.< Previous | Top | Next >