+ Reply to Thread
Results 1 to 8 of 8

Summing by colour and category

  1. #1
    Registered User
    Join Date
    06-03-2015
    Location
    UK
    MS-Off Ver
    MS Office 15
    Posts
    11

    Summing by colour and category

    I would like to build a formula that will evaluate the sum of a range of cells based on not only the category they relate to, but also on the colour that specific shells are shaded. I've attached an example spreadsheet of what I'm trying to do to help visualise this better.

    Any help would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Summing by colour and category

    heres UDF i came up with...its pretty specific to your example though


    Please Login or Register  to view this content.
    included the getbackground color UDF so you know where i get the random numbers from (which is colorindex)
    Attached Files Attached Files
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Summing by colour and category

    UDF

    Use in cell B22

    =SumCatCor($A22,$A$4:$M$18,B$21)

    Fill right + down

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 10-14-2015 at 11:35 PM.

  4. #4
    Registered User
    Join Date
    06-03-2015
    Location
    UK
    MS-Off Ver
    MS Office 15
    Posts
    11

    Re: Summing by colour and category

    Thanks humdingaling. I seem to be getting a 0 returned in the SumColor formula. Does the color index need to be a value, or can I simply concatenate the formulae together?

  5. #5
    Registered User
    Join Date
    06-03-2015
    Location
    UK
    MS-Off Ver
    MS Office 15
    Posts
    11

    Re: Summing by colour and category

    Thanks as well Jindon. I don't appear to have used the same colours in my original spreadsheet than the one I attached (my own fault). How do I obtain the different colour identifiers used in your UDF above?

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Summing by colour and category

    You need to replace the Color Numbers
    Please Login or Register  to view this content.
    You could obtain color number:
    1 Select the Colored cell that you want to get Color Number
    2 Open VBE(Visual Basic Editor) Alt + F11
    3 GoTo [View] - [ImmediateWindow]
    4 type
    ?ActiveCell.Interior.Color
    Then hit Enter key

    It will give you color number that you want.

    But this is not a smart way.
    I would prefer to get the color from cell in the function like this
    In cell B22:

    =SumCatCor($A22,$A$4:$M$18,B$21)

    Where B21 (Header) has colored like attached.

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

  7. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Summing by colour and category

    yes colorindex needs to be a number

    as per post #2, i included an additional UDF for you to get the colorindex
    see row 30 of my sheet, i used getbackgroundcolor() UDF
    the situation is similar to what Jindon Posts in post #6

    however, Jindon's new code in post #6 has it built in as well as making the UDF react to changes within the sheet
    i suggest you just take his version as it is a better version of what i had initially

  8. #8
    Registered User
    Join Date
    06-03-2015
    Location
    UK
    MS-Off Ver
    MS Office 15
    Posts
    11

    Re: Summing by colour and category

    That works a treat! Thanks for both of 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. Summing each category per month
    By stevewilde in forum Excel General
    Replies: 5
    Last Post: 04-25-2014, 10:01 PM
  2. [SOLVED] Summing Data by Week Ending and Category
    By cpalmer72 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-12-2013, 11:13 PM
  3. Summing Data by Week Ending and Category
    By cpalmer72 in forum Excel General
    Replies: 1
    Last Post: 10-03-2013, 02:30 PM
  4. Bar Chart - how to colour specific category axis values.
    By Richard Buttrey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2010, 08:58 AM
  5. Replies: 0
    Last Post: 08-28-2005, 11:07 AM
  6. [SOLVED] Summing Data based on Its Category
    By sip8316 in forum Excel General
    Replies: 2
    Last Post: 05-24-2005, 03:06 PM
  7. summing an array by product category
    By BLW in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-18-2005, 07:06 PM
  8. Colour code category axis labels
    By MattShoreson in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-02-2005, 11:32 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