Results 1 to 9 of 9

Add cells based on background colour - Glitch

Threaded View

  1. #1
    Registered User
    Join Date
    11-27-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    10

    Add cells based on background colour - Glitch

    Hi All,

    I recently created a macro (with a little help from some forums) that was designed to sum a row of cells IF the cell formatting used a particular colour in the background. It worked a treat, and this is what it looked like

    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

    It does what I want it to do, except when I use 'undo'. For instance, I change one of the cells to my special background colour (blue) - the sum changes as planned, but then if I click undo, the background changes back to the old colour (grey) but instead of the sum changing again, it keeps the new total. i.e the sum of blue cells and one grey cell. I want it to only show me the totals of my blue cells.

    Can anyone suggest how I ought to tweak the above code so that it will always show the correct total?
    Last edited by elliem19; 06-07-2016 at 12:45 AM. Reason: To comply with Rule 3

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Search cells based on student name, cell background colour and return a tally for colour
    By drof_06 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2016, 04:31 AM
  2. Returning value of cells based on another cells background colour
    By Prankster182 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2015, 09:19 AM
  3. copy row from one worksheet to another based on background colour in row
    By willcmuk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2012, 08:47 AM
  4. Replies: 7
    Last Post: 07-16-2012, 05:10 PM
  5. [SOLVED] sum up cells by background colour
    By Mengo85 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2012, 01:27 PM
  6. Filtering based on existing background colour
    By orga in forum Excel General
    Replies: 1
    Last Post: 07-13-2009, 07:46 AM
  7. IF formula based on background cell colour
    By mr_teacher in forum Excel General
    Replies: 1
    Last Post: 11-28-2007, 10:44 AM

Tags for this Thread

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