+ Reply to Thread
Results 1 to 15 of 15

Sum Cells Based on Background Color

  1. #1
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Sum Cells Based on Background Color

    Can anyone help me to get the total amount based on the colour of cell? Thanks for advance.
    Attached Files Attached Files

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Sum Cells Based on Background Color

    It's worse idea because if you only change color calculation value doesn't change till F9 or any other events for calculation will be done.
    there are many variants and here one of them
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by BMV; 02-05-2020 at 02:17 AM.

  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,427

    Re: Sum Cells Based on Background Color

    If you can tell us what the criteria is for determining if a cell is to be red we might be able to total from that criteria.

    For instance: if the cells are colored red because the values in column B are greater than 1 then this could work.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Other wise you would require VBA. There are people here who can do that. Unfortunately I am not one of them.
    Dave

  4. #4
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Sum Cells Based on Background Color

    Quote Originally Posted by alferd324 View Post
    . . . total amount based on the colour of cell . . .?
    This sort of thing is unreliable. For example, if you have 1 to 10 in B3:B12, you want to sum cells with red background color, and B5, B7 and B10 have red background color, so the sum would be 16. Using volatile VBA user-defined functions, you could enter a formula like =MyColorSum(B3:B12,"red") and it'd return 16, but if you then change the background color of any of these 3 cells to something else or change the background color of any of the other 7 cells to red, the formula WILL NOT RECALCULATE until you press [F9] (assuming the UDF were volatile) or reenter the formula.

    You'd be A LOT BETTER OFF using an extra column to enter, say, X for rows you want to include, then use conditional formatting based on formulas referring to these new entry cells to set the conditional formatting color for the value cells, then use SUMIFS(value_range,new_entry_range,"X") to sum up the selected values. Putting this differently, you're BEGGING FOR PROBLEMS basing any calculations on formatting.

  5. #5
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Re: Sum Cells Based on Background Color

    Hi thanks for your suggestion. Can I know why this code can't work in my other file, as I already copy the code into my Visual Basic library of this file? And how to find the number of Color code?

  6. #6
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Re: Sum Cells Based on Background Color

    Quote Originally Posted by BMV View Post
    It's worse idea because if you only change color calculation value doesn't change till F9 or any other events for calculation will be done.
    there are many variants and here oe of them
    Please Login or Register  to view this content.
    Hi thanks for your suggestion. Can I know why this code can't work in my other file, as I already copy the code into my Visual Basic library of this file? And how to find the number of Color code?

  7. #7
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Sum Cells Based on Background Color

    alferd324 .it's example but not code for distribute. For color code I prefer to use additional argument with cell was formatted.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Re: Sum Cells Based on Background Color

    Quote Originally Posted by BMV View Post
    It's worse idea because if you only change color calculation value doesn't change till F9 or any other events for calculation will be done.
    there are many variants and here one of them
    Please Login or Register  to view this content.
    Quote Originally Posted by BMV View Post
    alferd324 .it's example but not code for distribute. For color code I prefer to use additional argument with cell was formatted.

    Please Login or Register  to view this content.
    Can you make it work on the Colour Fill by conditional formatting as it only works in fill colour manually?

  9. #9
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Sum Cells Based on Background Color

    The string must be changed but I cant check it now
    Please Login or Register  to view this content.
    But in the case you use conditional format then you can use sumif(s) with the same conditions.

  10. #10
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Re: Sum Cells Based on Background Color

    Quote Originally Posted by BMV View Post
    The string must be changed but I cant check it now
    Please Login or Register  to view this content.
    But in the case you use conditional format then you can use sumif(s) with the same conditions.
    Sorry it can't work for me

  11. #11
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Sum Cells Based on Background Color

    Yes, i'v checked and DisplayFormat is not available for UDF from worksheet.

  12. #12
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Sum Cells Based on Background Color

    If the colour is from a conditional format, I refer you to post 3. it is possible to sum based on the conditional format if we know what it is. Which is why an attachment like suggested in the yellow bar is hugely helpful. your example doesn't contain the conditional formats

  13. #13
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Re: Sum Cells Based on Background Color

    Quote Originally Posted by davsth View Post
    If the colour is from a conditional format, I refer you to post 3. it is possible to sum based on the conditional format if we know what it is. Which is why an attachment like suggested in the yellow bar is hugely helpful. your example doesn't contain the conditional formats
    Below is the attachment that I applied the conditional formatting into it. In this file, I enter the serial number in sheet 2 and then the same serial number will be highlighted in sheet 1
    Attached Files Attached Files

  14. #14
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Sum Cells Based on Background Color

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    01-28-2019
    Location
    Malaysia
    MS-Off Ver
    Office 365
    Posts
    160

    Re: Sum Cells Based on Background Color

    Quote Originally Posted by BMV View Post
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks for your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to Sum Cells based on Background Color?
    By real20 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-23-2020, 01:34 PM
  2. [SOLVED] Sum cells based on background color
    By Punxatawny in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2018, 05:23 PM
  3. sum cells based on background color
    By Krueger in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 07-27-2017, 11:12 AM
  4. 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
  5. 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
  6. [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
  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