Results 1 to 2 of 2

Sum cells based on background color

Threaded View

  1. #1
    Registered User
    Join Date
    06-23-2017
    Location
    Fort Collins, CO
    MS-Off Ver
    Office 2010
    Posts
    29

    Sum cells based on background color

    Yesterday I found this UDF designed to sum only the cell that match a specific background color.

    Function SumByColor(CellColor As Range, rRange As Range)
    Dim cSum As Long
    Dim ColIndex As Integer
    ColIndex = CellColor.Interior.ColorIndex
    For Each cl In rRange
      If cl.Interior.ColorIndex = ColIndex Then
        cSum = WorksheetFunction.SUM(cl, cSum)
      End If
    Next cl
    SumByColor = cSum
    End Function
    For some reason it's rounding the result instead of giving a true sum. I assume it has something to do with the line "Dim ColIndex As Integer" but I am clueless about how to read this code. Other than the rounding it works great, can someone please tell me what to change so that it provides the real sum and not a rounded integer?
    Last edited by Punxatawny; 10-03-2018 at 05:06 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. sum cells based on background color
    By Krueger in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 07-27-2017, 11:12 AM
  2. How to add cells just based on their color background?
    By meirelesj in forum Excel General
    Replies: 7
    Last Post: 07-28-2015, 07:04 AM
  3. Change cell background color based on another cells background color
    By Queo in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 06-10-2014, 05:28 AM
  4. [SOLVED] Sum and average cells based on background color
    By Kaitlynn in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-22-2013, 12:51 PM
  5. [SOLVED] Color Index to sum up cells based on background color
    By jph89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2013, 03:23 PM
  6. Replies: 3
    Last Post: 05-02-2012, 09:08 AM
  7. Count Cells Based On A Background Color
    By NSTurk725 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2010, 11:29 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