+ Reply to Thread
Results 1 to 9 of 9

Sum column with only coloured cells

  1. #1
    Registered User
    Join Date
    09-18-2008
    Location
    Australia
    Posts
    37

    Sum column with only coloured cells

    Hi All

    I have a feeling that this is a dumb beginners question.

    I have a worksheet containing a large column with random coloured (red) cells, how can I Sum only the coloured cells and then only the empty cells?

    TIA thalt
    Last edited by VBA Noob; 11-15-2008 at 06:39 AM.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Excel doesnt have a built in function to do this, so you will need to use a user defined function. This is the code that I wrote to sum colored and un colored cells.

    Enter this code into a general module. The function takes two arguments: the first argument is the Range, the second is TRUE or FALSE (True sums colored cells, FALSE sums uncolored only).

    A formula would look like: =ADDCLRS(A1:A100,TRUE)

    Code

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-18-2008
    Location
    Australia
    Posts
    37

    Sum column with only coloured cells

    Hi BigBas

    I couldn't get the formula to work and I do not know how to use macros.

    I will have to study up on how to use macros.

    Any other formulas.

    Thanks for the reply at least I know it wasn't a simple question. Thalt

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    This is a new function, not a macro. You have to add it into your Sheet as a usable function.

    How to Create Excel User Defined Functions
    1. Open up your workbook.
    2. Get into VBA (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet.
    7. Use the functions (They will appear in the Paste Function dialog box, Shift+F3, under the "User Defined" category)
    If you want to use a UDF in more than one workbook, you can save your functions in your own custom add-in. Simply save your excel file that contains your VBA functions as an add-in file (.xla). Then load the add-in (Tools > Add-Ins...).

    Warning! Be careful about using custom functions in spreadsheets that you need to share with others. If they don't have your add-in, the functions will not work when they use the spreadsheet. Best to store those UDFs in the sheets themselves.

    (Source)
    ===========
    BigBas already suggested how this new function would now work as a formula:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 11-15-2008 at 12:35 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    09-18-2008
    Location
    Australia
    Posts
    37

    Sum column with only coloured cells

    Hi BigBas & JBeaucaire

    I have followed the directions and got the formula =AddClrs(T3358:T3581,"T") which gave me a zero, I retyped the "T" as TRUE and still got a zero.

    As I had to deliver an answer I put a one in every red cell and the formula computed the number in column D.

    As a test bench I did a small section in Column G but I could only get it to work if I put 1s in also. The 1s without a colour, and the colours without a 1, were not counted

    Am I doing something wrong? thalt
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    I couldn't get AddClrs to work either. Here's another UDF called ColorFunction. Add it in a Module of its own.
    Please Login or Register  to view this content.
    You'll need to set a color reference cell to compare to. Go to AA1 and set it to the red color you're counting. Now this formula will work:
    Please Login or Register  to view this content.
    If you set the last parameter to TRUE, it will SUM the values in the cells that match the search color. Cool. I just tested this on your sheet and it works great.

    FALSE = Count the number of cells that have a specific color background.
    TRUE = Sum the contents of cells with the specific background color.
    Last edited by JBeaucaire; 11-15-2008 at 05:37 AM.

  7. #7
    Registered User
    Join Date
    09-18-2008
    Location
    Australia
    Posts
    37

    Sum column with only coloured cells

    Thanks JBeaucaire
    That works perfectly, as my column has over 5000entries you can see why I wanted a formulaic way of doing it.

    Plus I have now fiddled with my first UDF so I am sure it will not be my last.

    Thanks for both your help it is much appreciated. thalt

    PS I cannot find the Solved button so I will have to return to get the directions to do it.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Edit your first post, then click the Prefix box to the left of the thread title.

  9. #9
    Registered User
    Join Date
    01-09-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Sum column with only coloured cells

    Tried it but unfortunately, I just realized my version is in french and it is 2010... I will keep on searching!

+ 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