+ Reply to Thread
Results 1 to 19 of 19

sum certain cells based on critieria

  1. #1
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    sum certain cells based on critieria

    Good morning,

    I need some major help with this. I have been trying for months to figure it out.

    In Column A, I have 2 different kinds of text, "3.2" and "3.6". There is no patten to the order.

    In Column B, there is a number (lets say either a 1 or a 2).

    In cells C1 & C2, I have "3.2" and the number 5, respectively. I want it to find 5 "3.2" rows and add the number's from column B for those 5 rows only.
    Last edited by westchr5; 01-15-2015 at 11:48 AM.

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: sum certain cells based on critieria

    Hi and welcome to the forum!

    Which 5 rows? The first such 5?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Hi Xor,

    The first 5 rows that contain the text "3.2". Because the pattern is random, it could be rows 1,4,5,6,10.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,942

    Re: sum certain cells based on critieria

    Hi, welcome to the forum

    Perhaps add a helper to count the 3.2's, and then use sumifS() to add up what you want, based on that?

    If you still have a problem, upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: sum certain cells based on critieria

    Would this work?

    =SUMPRODUCT((COUNTIF(INDIRECT("A1:A"&ROW(A1:A10)),C1)<=C2)*(A1:A10=C1)*B1:B10)

    Alter the column A and B ranges to fit your ranges.

    Hope this helps!
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: sum certain cells based on critieria

    Or, assuming your use of quotation marks (e.g. "3.2","3.6") was not indicative of the fact that those values are text values, array formula**:

    =SUM(IF(A1:A10=C1,IF(ROW(A1:A10)<=SMALL(IF(A1:A10=C1,ROW(A1:A10)),5),B1:B10)))

    Obviously if your range is not A1:A10 then amend accordingly (though I strongly recommend you keep the end range reference - 10 here - as small as feasibly possible; and certainly don't use entire column references in an array formula).

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,942

    Re: sum certain cells based on critieria

    2 more options...
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Version 1 Helper Version 2
    2
    1
    3.2
    1
    24
    1
    3.2
    1
    24
    3
    2
    3.2
    2
    2
    3.2
    2
    4
    3
    3.6
    2
    3
    3.6
    5
    4
    3.6
    2
    4
    3.6
    6
    5
    3.2
    3
    5
    3.2
    3
    7
    6
    3.6
    3
    6
    3.6
    8
    7
    3.2
    4
    7
    3.2
    4
    9
    8
    3.6
    4
    8
    3.6
    10
    9
    3.2
    5
    9
    3.2
    5
    11
    10
    3.2
    6
    10
    3.2
    6

    D2=SUMIFS($A$2:$A$11,$B$2:$B$11,3.2,$C$2:$C$11,"<6")
    I2=SUMIF(H2:H11,"<6",F2:F11)

  8. #8
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Attached is a sample worksheet. The highlight cells represent the cells that should be added together because they are the first 4 "3.2" rows.


    Capture.PNG

    Book1.xlsx

    Edit: When I posted this a few more responses popped up. I'll try those suggestions now.

  9. #9
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: sum certain cells based on critieria

    This should do the trick:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Mcmahobt,

    Your formula is perfect... except for one issue. The cells that contain the text, 3.6 or 3.2, have a formula. (See below). If a cell has a formula, it causes an error message using your formula. If I manually type in 3.6 or 3.2, it will work.

    PHP Code: 
    =IFERROR(IF(MID(K28,12,2)+0=32,"3.2",IF(MID(K28,12,2)+0=36,"3.6","Other")),""
    Any ideas on how to correct this?

  11. #11
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: sum certain cells based on critieria

    Can you upload a sample workbook that recreates the problem?

  12. #12
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Book2.xlsx

    See attached. The Value Error message is where I was testing formula

  13. #13
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    You can see my old method in the excel sheet. Which does read the text. However, it doesn't know how to differentiate the rows and such.

  14. #14
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: sum certain cells based on critieria

    See the attached workbook for fix. You had a few conflicting syntax errors with some of your IF statements that was throwing off the sumproduct. The formula is located in cell AD22.

    Hope this helps!
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Book3.xlsx


    Thank you! I have hopefully one last question. When I took the excel sheet you uploaded, and expanded the formula to include more rows, it stopped working for any quantity less than 6 in AD4. See attached.

  16. #16
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Whoops. I should mention that I moved the formula to AC5 & AC6

  17. #17
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,942

    Re: sum certain cells based on critieria

    I have not looked at the files in the other posts, but I would suggest that change your formula so that the snaswers are values not text...

    =IFERROR(IF(MID(K28,12,2)+0=32,"3.2",IF(MID(K28,12,2)+0=36,"3.6","Other")),"")
    change to...
    =IFERROR(IF(MID(K28,12,2)+0=32,3.2,IF(MID(K28,12,2)+0=36,3.6,"Other")),"")
    or maybe even...
    =IFERROR(--MID(K28,12,2)/10,"")

  18. #18
    Registered User
    Join Date
    09-23-2014
    Location
    Detroit, MI
    MS-Off Ver
    office 10
    Posts
    16

    Re: sum certain cells based on critieria

    Book2.xlsx

    Okay. I am still working to solve the problem. Attached is mcmahobt's version, but I replicated the error I am experiencing. In mcmahobt's version there are 2 data entries. In my updated version, I have 3 entries. For whatever, it will not calculate properly. If the user selects "3.6" and inputs 2 blocks are in the bank, it says 0. It only seems to work at the minimum and maximum.

    Quote Originally Posted by mcmahobt View Post
    See the attached workbook for fix. You had a few conflicting syntax errors with some of your IF statements that was throwing off the sumproduct. The formula is located in cell AD22.

    Hope this helps!

  19. #19
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: sum certain cells based on critieria

    Are you willing to add a helper column for your data to ease this process? If you are, check the attached workbook. I have hidden column M which contains the helper formula. Cell AE22 contains the results I believe you are looking for.
    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. Returning value in row based on Critieria
    By lkoll in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-06-2013, 03:43 AM
  2. Macro to populate a table based on a selection critieria
    By jay170878 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2012, 09:56 AM
  3. [SOLVED] Sum of data based on two critieria
    By JohnDowds in forum Excel General
    Replies: 5
    Last Post: 06-07-2012, 03:23 AM
  4. Choose a value based on 2 cell Critieria
    By raghuram_g in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 10-26-2011, 12:12 PM
  5. protect cell based on another cells critieria?
    By djarcadian in forum Excel General
    Replies: 7
    Last Post: 03-07-2009, 02:06 PM

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