+ Reply to Thread
Results 1 to 2 of 2

Counting cells with a specific range

  1. #1
    teresa
    Guest

    Counting cells with a specific range

    This function is taken from C Pearsons site and it counts the number of cells
    within
    a range. Can someone explain the asterixxed lines below
    Thanks

    #CountByColor = CountByColor - _
    # (Rng.Font.ColorIndex = WhatColorIndex)
    #Else
    # CountByColor = CountByColor - _
    # (Rng.Interior.ColorIndex = WhatColorIndex)



    Function CountByColor(InRange As Range, _
    WhatColorIndex As Integer, _
    Optional OfText As Boolean = False) As Long
    '
    ' This function return 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

    For Each Rng In InRange.Cells
    If OfText = True Then
    CountByColor = CountByColor - _
    (Rng.Font.ColorIndex = WhatColorIndex)
    Else
    CountByColor = CountByColor - _
    (Rng.Interior.ColorIndex = WhatColorIndex)
    End If
    Next Rng

    End Function



  2. #2
    Bob Phillips
    Guest

    Re: Counting cells with a specific range

    It is simply working out whether it counts the cells that meet the required
    colour, or whether to count the cells whose text meets the colour.

    The function has an optional parameter OfText that you can set to True to
    count the cell text colour.

    --
    HTH

    Bob Phillips

    "teresa" <[email protected]> wrote in message
    news:[email protected]...
    > This function is taken from C Pearsons site and it counts the number of

    cells
    > within
    > a range. Can someone explain the asterixxed lines below
    > Thanks
    >
    > #CountByColor = CountByColor - _
    > # (Rng.Font.ColorIndex = WhatColorIndex)
    > #Else
    > # CountByColor = CountByColor - _
    > # (Rng.Interior.ColorIndex = WhatColorIndex)
    >
    >
    >
    > Function CountByColor(InRange As Range, _
    > WhatColorIndex As Integer, _
    > Optional OfText As Boolean = False) As Long
    > '
    > ' This function return 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
    >
    > For Each Rng In InRange.Cells
    > If OfText = True Then
    > CountByColor = CountByColor - _
    > (Rng.Font.ColorIndex = WhatColorIndex)
    > Else
    > CountByColor = CountByColor - _
    > (Rng.Interior.ColorIndex = WhatColorIndex)
    > End If
    > Next Rng
    >
    > End Function
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1