+ Reply to Thread
Results 1 to 13 of 13

How to automatically sum based upon interior fill color when the fill color changes

  1. #1
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    How to automatically sum based upon interior fill color when the fill color changes

    Hi,
    I have a budget spreadsheet. Each month, users are able to change the interior fill (Green = ok, Yellow = monitor, Red = bad). The spreadsheet has multiple column (B10:E79) and totals on row 80 for each column. On row 82 in each column I wish to have a total for all the green filled cells, row 83 for the yellow filled cells, and row 84 for the red filled cells. Each month, when the interior fill changes, the totals in rows 82, 83, and 84 need to be automatically updated.

    I know Excel does not consider changing a cell's color to be significant to the calculation; thus, won't recalculate a formula when a cell color is changed. Simply changing a cell color does not cause a calculation, so the function is not recalculated, even with Application.Volatile True. Knowing this, how can I get the totals in rows 82, 83, and 84 need to be automatically updated each time the fill color changes? Assume the Color Index is green=4, yellow = 6, red = 3) if that helps.

    Suggestions? Thanks for your help!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Murman01,

    Does the user change the cell color using a drop down list or manually?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Right now, the user can manually change the cell color using the "Fill Color" option, but I'm open to suggestions on ways. Ideally, the user would be restricted to the three colors I mentioned in my original post so as to avoid various shades of red, for example, on the same sheet as some people may interpret a light shade as being "less bad" than a darker shade of red when in reality "red is red"! Example, if the user enters $100 in cell B20, the user has the option of only choosing green, yellow, red, or blank (no color).

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Murman01,

    I developed a VBA macro that uses a Data Validation drop down list. It has Red, Yellow, Green, and None. When the user changes the value of the cell the background color will remain the same. The macro is shown below and has been added to the attached workbook.

    Worksheet Change Event Procedure Code
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Thanks a bunch Leith! This works pretty well, but it is not quite right for three reasons in order to resolve the overriding problem I am encountering in item #3 below:

    1) If the user enters the dollar value and then selects a color from the dropdown before pressing the enter key, then a run-time error ‘1004’ “Method ‘Undo’ of object ‘_Application’ failed.

    2) After entering a dollar value, the user has to press “enter” twice for the cursor to move down to the next cell. If the user forgets to press “enter” twice, it will lead to data entry errors.

    3) In the example you provided, I need row 13 to total the green values in that column, row 14 to total the yellow values in that column, and row 15 to total the red values in that column whenever the dollar value changes or the background color changes.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Murman01,

    Thanks for listing what needed to be changed. All the errors have been corrected and the summing cells are now updated whenever a cell value is changed or the color changed.

    Try this version out and let me know if you find anything else theat needs to be addressed.

    Here is the code that has been added to the attached workbook...

    Worksheet Change Event Code
    Please Login or Register  to view this content.

    Module1 Macro Code
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 01-30-2017 at 11:42 PM.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    As a side note, I still cannot post attachments due to some B.S. with the Sucuri proxy server. Got to love these duplicate posts though!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Murman01,

    Hooray, I can attach files again! Here is the new workbook...

  9. #9
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Leith,
    Thanks for persevering and attaching the file. We’re just about there! The “run-time error 1004” still occurs, though.

    If the user puts a dollar value in Column A, presses ENTER and then goes back to that cell to select a color from the dropdown, everything works fine.

    If the user selects a color from the dropdown then puts a dollar value in Column A and presses ENTER, everything works fine.

    If the user puts a dollar value in Column A and then immediately selects a color from the dropdown before pressing the ENTER key, I get a “run-time error ‘1004’ “Method ‘Undo’ of object ‘_Application’ failed”. The totals in rows 13:15 are updated just before the error message occurs, though.

    Also, if the user accidently puts anything other than numeric values in Column A, presses ENTER and then goes back to that cell to select a color from the dropdown, a “Run-time error ‘13’: Type mismatch” error occurs. I can’t put in a second data validation in those cells for data entry because of the dropdown list already in use.

    By the way, your SumByColor() solution is pretty slick. Thanks!

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Murman01,

    Using the updated workbook and code that I posted, I cannot reproduce the errors you mention. There must be something different between the workbook you are using and the one posted. If you post a copy of your workbook, I can troubleshoot the problem. Thanks.

  11. #11
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Leith,
    I appreciate the time you're taking to assist me. I've attached my workbook per your request.

    If you put your cursor anywhere in A1:A10, enter any dollar value and then before pressing ENTER, select a color from the dropdown...you'll get the “run-time error 1004” message.

    If you put your cursor anywhere in A1:A10, enter a non-numeric item, press ENTER, then go back to that cell to select a color from the dropdown...you'll get the "Run-time error ‘13’: Type mismatch" message.

    Much thanks!
    Attached Files Attached Files

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hello Murman01,

    Thanks for posting the file. I will be out for a few hours. When I return. I will see what I can find that is causing the issues.

  13. #13
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: How to automatically sum based upon interior fill color when the fill color changes

    Hi Leith,
    I tried sending you a private message, but it doesn't look like it happened (nothing in my "sent" box).

    I'm wondering if you've had an opportunity to check further into the issues we were working on a couple weeks ago. I'm starting holidays on Feb 15 and would like to have these issues resolved for my end users before I leave. I recognize your expertise is in high demand, so if you don't have the time to graciously help me any further, I'll understand. Please let me know so I can plan for my next steps. Thanks! Murray

+ 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. Delete CF fill color, replace with regular fill color. Short code, can't figure it out!
    By excelfriend1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-11-2016, 09:03 PM
  2. [SOLVED] How to fill color cells based on another cell's fill color?
    By putritersenyum in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-22-2016, 08:58 AM
  3. [SOLVED] Click oval option button to fill/unfill color, also change border color to match fill
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2015, 08:29 PM
  4. [SOLVED] change fill color of a range of cells based on color of a cell?
    By DarMelNel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2014, 04:48 PM
  5. "Fill" i.e. interior color a row based on a date value within that row
    By LiLi1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-11-2012, 06:54 AM
  6. "If" and Syntax to change font and fill (interior) color based on cell value
    By jdfjab in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-17-2012, 10:29 AM
  7. Replies: 3
    Last Post: 07-08-2010, 06:48 PM

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