+ Reply to Thread
Results 1 to 11 of 11

Formula to Sum numbers depending on text in other cells

  1. #1
    Registered User
    Join Date
    10-15-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    49

    Formula to Sum numbers depending on text in other cells

    Hi I'm trying to show a summary of some direct debit payments across 12 or more months.

    I have a column called SALP09 which is the sale price (total)... a column called PAID and a COLUMN called OWED.

    I then have 2 columns for each direct debit payment, the amount and the status of the payment.

    The status of the payment will either be S - Sent, F - Failed - (failed code), O - Paid by other means. So its the first letter which is the key to the payment status.

    I'm looking for some formula to calculate the total PAID depending on the status in the cell next to it... and then from there I can easily calculate what is owed.

    Any help is much appreciated!

    I have attached a sample
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Formula to Sum numbers depending on text in other cells

    Hello,

    Assuming you want to calculate G2 and G3, how will you do this, for example if the status is S, F or O then add the number in the left of it to the sum?
    (copy pasta from Ford)
    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

    Regards,
    Lem

  3. #3
    Registered User
    Join Date
    10-15-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Formula to Sum numbers depending on text in other cells

    Yea... So I was thinking something like =SUMIF(MID(J2,1,1),"S",I2) Although I just tried that and I've got the formula wrong.

    But yea summing in G2 depending on the status text in the other cells

  4. #4
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Formula to Sum numbers depending on text in other cells

    In case you want to sum the number if the cell to the right of it (under Status column) is "S", then this formula might be the one you want
    Please Login or Register  to view this content.
    Just paste it on G2 and drag it down.

  5. #5
    Registered User
    Join Date
    10-15-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Formula to Sum numbers depending on text in other cells

    Hi Lem.. that's a useful formula! It worked. I'm not too sure what the two -- mean. If I wanted to expand the formula to also sum if the text was "O"... so "O" or "S" is this easy to add in with a comma or something or would I need to do an OR statement?

  6. #6
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Formula to Sum numbers depending on text in other cells

    Then it will be something like this
    Please Login or Register  to view this content.
    The -- in front of a formula will make it return 1 or 0 instead of TRUE or FALSE, in this case I am making the SUMPRODUCT making an array of 0 and 1 with the condition, and multiply it with the corresponding cell to the left of it (that's why the mismatch in cell reference).
    Last edited by Lemice; 05-11-2013 at 08:12 AM. Reason: fixing formula

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Formula to Sum numbers depending on text in other cells

    Hello Lem,

    Those last two formulas will always return zero because all conditions have to be true and the text values in J2:AF2 obviously can't begin with both "S" and "O", you'll need + instead of *, i.e.

    =SUMPRODUCT((LEFT(J2:AF2,1)="S")+(LEFT(J2:AF2,1)="O"),I2:AE2)

    or you can use SUMIF with wildcards like this

    =SUM(SUMIF(J2:AF2,{"S*","O*"},I2:AE2))
    Audere est facere

  8. #8
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Formula to Sum numbers depending on text in other cells

    I totally forgot about it ... Thanks daddylonglegs for pointing it out, I have fixed the formula on post #6

  9. #9
    Registered User
    Join Date
    10-15-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Formula to Sum numbers depending on text in other cells

    Do you think both formulas should calculate around the same time when dealing with larger data...

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Which do you think is best to use?
    Last edited by ExcelGal; 05-11-2013 at 08:11 AM.

  10. #10
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Formula to Sum numbers depending on text in other cells

    I suggest using SUM with SUMIF.

    Generally COUNTIF and SUMIF are way faster than all kind of array formula that does the same thing (SUMPRODUCT)

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to Sum numbers depending on text in other cells

    Quote Originally Posted by ExcelGal View Post

    Which do you think is best to use?
    There is calculation timer code at this link:

    http://msdn2.microsoft.com/en-us/library/aa730921.aspx

    You can test the formulas and see for yourself which is better!
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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