+ Reply to Thread
Results 1 to 15 of 15

VBA: Auto sum by cell colour in a row

  1. #1
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    VBA: Auto sum by cell colour in a row

    Hi

    I'm trying to calculate totals in a row but want to split them out by cell colour (Green and Yellow) where any figures in yellow are totalled and any figures in Green are totalled seperately

    Any assistance will be appreciated

    Many thanks

    Craig

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,883

    Re: Auto sum by cell colour in a row

    Sorry - this can only be done with VBA, not formulae. What would make a cell one of these colours? Are they conditionally formatted, and if so, what are the rules? If, and only if this is the case, you'd be able to do this with a formula.
    Last edited by AliGW; 04-08-2020 at 06:11 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    Re: Auto sum by cell colour in a row

    The cells would be coloured manually when the information is inputted.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,883

    Re: Auto sum by cell colour in a row

    Then it can't be done without VBA code - sorry. Shall I move your thread to the VBA section?

  5. #5
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    Re: Auto sum by cell colour in a row

    Yes please. I've just had a look at VBA code!!!

    Thank you for pointing me in the right direction

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,883

    Re: VBA: Auto sum by cell colour in a row

    Done.

    The only way to do it without VBA would be to have a helper column (or row) to identify the green and yellow numbers with a number or letter.

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: VBA: Auto sum by cell colour in a row

    Using UDF
    Please Login or Register  to view this content.
    Use as formula in cell as follows

    = SumbyColor(a coloured cell in the range such as "B4", The range containing the coloured cells such as "b1:b36") ie: =SumbyColor(B4,b1:b36)
    Attached Images Attached Images
    Last edited by nigelog; 04-08-2020 at 08:41 AM.

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: VBA: Auto sum by cell colour in a row

    Try the attached, it works with the Worksheet_Change event.
    The area covered is 20 rows x 10 columns, you have to choose your colour while in the cell prior to number entry.
    Totaling in columns 11 & 12
    I could not see the yellow clearly so at present it is set 'red', the colours are from the 'standard colors' not 'theme'
    Note:- the green in the standard bar is not the primary (255) green (MS confuses us once again)
    There has to be an easier way as I found the data entry method very frustrating.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    Re: VBA: Auto sum by cell colour in a row

    That is excellent. Thank you. I am trying to put a decimal place in for certain numbers, this is rounded up at present. How can I change that to display the exact figure?

  10. #10
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    Re: VBA: Auto sum by cell colour in a row

    Quote Originally Posted by torachan View Post
    Try the attached, it works with the Worksheet_Change event.
    Thank you. I'm going by the colour of the cell rather than the text in the call. Thanks for helping though, most appreciated
    Last edited by AliGW; 04-08-2020 at 09:40 AM. Reason: Please don't quote unnecessarily!

  11. #11
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    Re: VBA: Auto sum by cell colour in a row

    Quote Originally Posted by torachan View Post
    Try the attached, it works with the Worksheet_Change event.
    That is excellent. Thank you. I am trying to put a decimal place in for certain numbers, this is rounded up at present. How can I change that to display the exact figure?
    Last edited by AliGW; 04-08-2020 at 09:54 AM. Reason: Please don't quote unnecessarily!

  12. #12
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: VBA: Auto sum by cell colour in a row

    Add function to a standard module and change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-17-2019
    Location
    Jersey
    MS-Off Ver
    365
    Posts
    17

    Re: VBA: Auto sum by cell colour in a row

    Quote Originally Posted by nigelog View Post
    Add function to a standard module and change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Perfect, Thank you

  14. #14
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: VBA: Auto sum by cell colour in a row

    Glad to help. Thanks for rep points

  15. #15
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: VBA: Auto sum by cell colour in a row

    Highlight the area (range) and format in normal manner to number of decimal places you require.
    I have altered the attached file to fill the cell interior colour (the green is 'light green' the numbers show up better)
    Attached Files Attached Files

+ 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. Auto highlight row & column of active cell without deleting existing cell colour
    By claire_wilson in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-22-2017, 08:31 PM
  2. [SOLVED] Auto Number based on cell colour
    By turist in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-03-2013, 08:28 PM
  3. auto send email with cell background colour
    By vipulhumein in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2013, 03:25 PM
  4. Auto Colour cells if a DATE is in adjacent cell.
    By michaelrusk in forum Excel General
    Replies: 9
    Last Post: 03-04-2013, 07:53 AM
  5. Replies: 1
    Last Post: 05-06-2010, 03:09 AM
  6. Auto change colour of cell when text / letter entered into cell
    By Nik_AU in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2007, 07:36 AM
  7. auto changing cell colour
    By YYX99 in forum Excel General
    Replies: 5
    Last Post: 05-16-2007, 10:56 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