Results 1 to 2 of 2

Modifying a Custom Function that is Summing Cells based on Fill Colour

Threaded View

  1. #1
    Registered User
    Join Date
    11-12-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    Modifying a Custom Function that is Summing Cells based on Fill Colour

    I have a Spreadsheet that i would like to be able to carry out a sum of Range of cells that are equal to a certain colour and also contain no text/numbers. I have come across some code that has created a Function that works perfect for summing the cells of a certain colour. I now need to modify it to also make sure it excluded cells that have text/numbers in them.

    This below is what i found online and have used so far.

    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
    Last edited by BLN355; 10-04-2014 at 09:22 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Change Shape Fill colour based on cells values.
    By pipoliveira in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-26-2020, 09:21 AM
  2. Replies: 1
    Last Post: 06-20-2014, 05:21 AM
  3. Changing the fill colour of 2 other cells based on another cell's outcome
    By Danny1982 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-29-2014, 11:22 AM
  4. Certain cells fill with colour based on the dates I enter (gantt chart style)
    By matticusbond in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-08-2014, 06:25 PM
  5. Calculating cells based on fill colour
    By JONNY981 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-21-2013, 11:59 AM

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