Results 1 to 6 of 6

Colour Function

Threaded View

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    56

    Colour Function

    Hi,

    I found a VBA code that counts how many coloured cells I have..but I cannot seem to make it work (see attached file). I added the module and typed in the formula...but it is not returning the value. I have attached the sheet.

    I am looking to count how many of three different colours appears in column B and the % it comes up. Can someone let me know what I am doing wrong?

    The code I used is:

    Option Explicit
    '''This is for counting the number of filled cells within a Range
    Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
        Dim rCell As Range
        Dim lCol As Long
        Dim vResult
        lCol = rColor.Interior.ColorIndex
        If SUM = True Then
            For Each rCell In rRange
                If rCell.Interior.ColorIndex = lCol Then
                    vResult = WorksheetFunction.SUM(rCell, vResult)
                End If
            Next rCell
        Else
            For Each rCell In rRange
                If rCell.Interior.ColorIndex = lCol Then
                    vResult = 1 + vResult
                End If
            Next rCell
        End If
       ColorFunction = vResult
    End Function
    Attached Files Attached Files
    Last edited by marshymell0; 06-28-2013 at 02:12 PM.

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