+ Reply to Thread
Results 1 to 9 of 9

VBA to sum cells by background colour

  1. #1
    Registered User
    Join Date
    04-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    17

    VBA to sum cells by background colour

    Hi
    Can someone help me with a bit of VBA code please as I can't get a formula to do what I need.
    I am trying to sum columns which have the background colour manually set to red or green.
    They track invoices awaiting payment in red and those paid in green and I change the colour
    when an invoice is paid. The code needs to sum the values in the red cells only, in order to
    show the total amount unpaid and automatically update the total when a cell colour is changed.
    There are 12 columns, one for each month so the code needs to work on each column independently.
    I'm using Excel 2010.

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: VBA to sum cells by background colour

    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Registered User
    Join Date
    04-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA to sum cells by background colour

    Hi KOKOSEK
    Thanks for your reply. I have tried your code which runs but I can't see any result in cell A1 when running it.
    However it gives a total amount across the full range and what I would like is a total for each column. I have
    attached a sheet showing how I would like it to look.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: VBA to sum cells by background colour

    The code is the same with KOKOSEK.
    But this one is added with looping for 12 times (for the months),
    and the code runs after activating Sheet1.

    I added one more Sheet, which is Sheet2.
    When you open the attached file, it will be Sheet1 and there's no SUM in A1 to L1 for the red cells yet.
    You need to go to Sheet2, then go back to Sheet1.
    After Sheet1 is activated, the code runs then show the SUM of the red cells in A1 to L1.

    Since I don't know how is your list is going look like,
    I just put 25 times looping to check each row in each column.
    Attached Files Attached Files

  5. #5
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: VBA to sum cells by background colour

    Quote Originally Posted by gasdesign View Post
    Hi KOKOSEK
    Thanks for your reply. I have tried your code which runs but I can't see any result in cell A1 when running it.
    However it gives a total amount across the full range and what I would like is a total for each column. I have
    attached a sheet showing how I would like it to look.
    That could be the reason.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA to sum cells by background colour

    KOKOSEK and karmapala

    I have edited the code and put it into the actual workbook and it does exactly what I need.
    Many thanks to both of you and I will mark the thread as solved.

  7. #7
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: VBA to sum cells by background colour

    Quote Originally Posted by gasdesign View Post
    Hi KOKOSEK
    Thanks for your reply. I have tried your code which runs but I can't see any result in cell A1 when running it.
    However it gives a total amount across the full range and what I would like is a total for each column. I have
    attached a sheet showing how I would like it to look.
    Please Login or Register  to view this content.
    on attached file works absolutely fine.
    Attached Files Attached Files

  8. #8
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: VBA to sum cells by background colour

    Happy to help.

  9. #9
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: VBA to sum cells by background colour

    glad to help gasdesign

+ 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. 2 colour background in cells. V16 for MacBook Pro
    By najw68 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 01-13-2019, 05:32 PM
  2. [SOLVED] format a cell background colour based on a manual background colour of an adjacent cell
    By Nampara in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2018, 04:03 PM
  3. [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
  4. Select cells by Background colour
    By WCE_123 in forum Excel General
    Replies: 2
    Last Post: 07-28-2015, 09:14 AM
  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. Counting cells containing a certain background Colour
    By paulizaz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-27-2008, 08:26 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