+ Reply to Thread
Results 1 to 17 of 17

Calculating cells based on fill colour

  1. #1
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Calculating cells based on fill colour

    Hi,

    I need a formula to calculate the average of a column of cells depending on the fill colour. For example column A as 20 rows of data, 5 of these are marked red. I need to find the average of these numbers and ignore the rest.

    I also need to do the same but for standard deviation, max value, min value and count. I had thought about trying to use colorfunction but im not sure how it could be combined with average etc. Is there an alternative?
    Last edited by JONNY981; 06-09-2011 at 06:48 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calculating cells based on fill colour

    Using Excel 2003 this is not possible without VBA
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Calculating cells based on fill colour

    Ok, thanks.

    Can you tell me how exactly to do it with VBA please?

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Calculating cells based on fill colour

    You might find this link useful
    Chip Pearson - Color Functions In Excel
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Calculating cells based on fill colour

    Or this one:

    Put into cell C2

    =averagered(A1:A20;3)
    or
    =averagered(A1:A20,3)

    Put into a macromodule:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by snb; 06-06-2011 at 09:20 AM.



  6. #6
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Calculating cells based on fill colour

    thanks, although I tried this and excel is telling me that the formula contains an error. any ideas why?

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Calculating cells based on fill colour

    Try changing the delimiter to a comma
    e.g.
    =averagered(A1:A20,3)

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calculating cells based on fill colour

    Here's an example

    ColourFunction(range with colour,range to calculate,option:average)

    Example of use, see attachment

    =ColourFunction($A$2,$A$2:$A$4,TRUE)

    A2 has a fill colour to calculate with
    A2:A4 is the range to average
    True is optional, if missed defaults to SUM
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Calculating cells based on fill colour

    Thanks.

    I changed the delimiter to a comma but then i got a #VALUE! error in the cell even though I am referencing the correct cells.

    The colourfunction option seems good, although can I use this for min, max and standard deviation too?

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calculating cells based on fill colour

    You can adapt the Function by using different worksheet Functions. I have a more complex version at home, I'll try to post it later

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Calculating cells based on fill colour

    See the attachment.
    Attached Files Attached Files

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calculating cells based on fill colour

    I've added some options to the Function
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Calculating cells based on fill colour

    Thanks for the help everyone. The colourfunction option seems to work the best for me.

    I know maybe this is slightly off the main subject but some of my data will have no red cells at all, and instead of a #VALUE! error I would like the cell to say 'No Breaks'. I attempted to write an if statement but I think im a bit off the mark...

    Please Login or Register  to view this content.

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calculating cells based on fill colour

    Use ISERROR.

  15. #15
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Calculating cells based on fill colour

    Ok thanks again!

  16. #16
    Registered User
    Join Date
    01-26-2013
    Location
    colorado
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Calculating cells based on fill colour

    Quote Originally Posted by royUK View Post
    I've added some options to the Function
    Hi royUK-I tried to download the attachment file and the formulas gave me a syntax error of #NAME?. Is this because I'm on a US version of Excel 2010? Any guidance would be greatly appreciated.

  17. #17
    Registered User
    Join Date
    08-20-2012
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Calculating cells based on fill colour

    Jonny,
    You ran in the the same issue that I have. When there are no cells colored I would like to have returned "0" not #value.
    Is there a way to do this right in the VBA code for the ColourFunction?

    Currently I add an extra colored cell and then subtract "1".

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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