+ Reply to Thread
Results 1 to 8 of 8

if statement for summing cells

  1. #1
    Gavin0268
    Guest

    if statement for summing cells

    Hi there
    I can do this in a clunky way (I think) but I'm looking for a more sensible
    method. I have an output spreadsheet from an instrument, and need to tinker
    with the numbers to display different things depending on the value of the
    cell.

    If the value is -ve, I display 'ND'; if the value is <0.2, I display TR.
    Otherwise then umber is displayed. So far so good.

    I then need to sum a number of these cells (say 4 of them). If there are any
    numbers (ie not all of the cells are ND or TR), I sum the numbers, ignoring
    ND or TR; if all the cells are ND I display ND, if all the cells are TR, or a
    mixture of ND or TR, I display TR. This is where I get stuck! Any ideas?

    Thanks in advance

  2. #2

    Re: if statement for summing cells

    Hi Gavin,

    I assume that by displaying "TR" you mean assigning value "TR" using if
    or any other condition.

    You can incorporate countif into your formula. I mean
    countif(a1:a4,"tr") will give you number > 0 if any "tr" is found in
    the range.

    Regards,
    Ivan


  3. #3
    Gavin0268
    Guest

    Re: if statement for summing cells

    Hi
    The individual cell IF statement is (e.g.)
    =IF(V48<0,"ND",IF(V48<0.2,"TR",V48)), where V48 is the original value.
    If we assume I'm then summing V46 to V49, say, I need to check if there are
    any numbers, and sum them (sum=sum of numbers, ignoring ND & TR); or all ND
    (sum=ND); or all TR or mix ND/TR (sum=TR).
    Do you think I need nested countif's for ND& TR's?


    "[email protected]" wrote:

    > Hi Gavin,
    >
    > I assume that by displaying "TR" you mean assigning value "TR" using if
    > or any other condition.
    >
    > You can incorporate countif into your formula. I mean
    > countif(a1:a4,"tr") will give you number > 0 if any "tr" is found in
    > the range.
    >
    > Regards,
    > Ivan
    >
    >


  4. #4

    Re: if statement for summing cells

    Hi,

    you don't need to check for numbers, sum ignores non-numerics.

    Supposing, that formula =IF(V48<0,"ND",IF(V48<0.2,"TR",V48)) is in W48
    (better to tell in range W46:W49, and you need the total in W50 and
    following:
    W50 = sum(W46:W49) - sum of numbers
    W51 = sumif(W46:W49,"ND",v46:v49) - sum of ND
    W52 = sumif(W46:W49,"TR",v46:v49) - sum of TR

    Does this help? Maybe I didn't understand your question fully (my
    understanding changed after your second post).

    Regards,
    Ivan


  5. #5
    Gavin0268
    Guest

    Re: if statement for summing cells

    Hi Ivan
    We're almost there, but maybe I'm not explaining very well! Here's some
    examples
    0.5,0.5,0.5,0.5: Sum=2
    0.5, 0.5, TR, ND: Sum = 1.0
    TR,TR,TR,TR: Sum = TR
    TR,ND,ND,TR: Sum = TR
    ND,ND,ND,ND: Sum = ND
    with obviously numerous variations.
    Thanks for the quick response


    "[email protected]" wrote:

    > Hi,
    >
    > you don't need to check for numbers, sum ignores non-numerics.
    >
    > Supposing, that formula =IF(V48<0,"ND",IF(V48<0.2,"TR",V48)) is in W48
    > (better to tell in range W46:W49, and you need the total in W50 and
    > following:
    > W50 = sum(W46:W49) - sum of numbers
    > W51 = sumif(W46:W49,"ND",v46:v49) - sum of ND
    > W52 = sumif(W46:W49,"TR",v46:v49) - sum of TR
    >
    > Does this help? Maybe I didn't understand your question fully (my
    > understanding changed after your second post).
    >
    > Regards,
    > Ivan
    >
    >


  6. #6
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094
    Gavin,

    Try something like this.

    =IF(SUM(F6:I6)>0,SUM(F6:I6),IF(AND(COUNTIF(F6:I6,"TR")>0,COUNTIF(F6:I6,"ND")>0),"TR",IF(AND(COUNTIF(F6:I6,"TR")>0,COUNTIF(F6:I6,"ND")=0),"TR","ND")))

    I used F6:I6 for my range to evaluate, change those as needed. In your sample data this returned 2,1,TR,TR and ND respectively. This assumes that if there are no numbers, there will always be "TR"'s and/or "ND"'s in the cells.

    Does that help?

    Steve

  7. #7
    Gavin0268
    Guest

    Re: if statement for summing cells

    Steve
    That looks perfect, just what I was after
    Many thanks
    Gavin

    "SteveG" wrote:

    >
    > Gavin,
    >
    > Try something like this.
    >
    > =IF(SUM(F6:I6)>0,SUM(F6:I6),IF(AND(COUNTIF(F6:I6,"TR")>0,COUNTIF(F6:I6,"ND")>0),"TR",IF(AND(COUNTIF(F6:I6,"TR")>0,COUNTIF(F6:I6,"ND")=0),"TR","ND")))
    >
    > I used F6:I6 for my range to evaluate, change those as needed. In your
    > sample data this returned 2,1,TR,TR and ND respectively. This assumes
    > that if there are no numbers, there will always be "TR"'s and/or "ND"'s
    > in the cells.
    >
    > Does that help?
    >
    > Steve
    >
    >
    > --
    > SteveG
    > ------------------------------------------------------------------------
    > SteveG's Profile: http://www.excelforum.com/member.php...fo&userid=7571
    > View this thread: http://www.excelforum.com/showthread...hreadid=538382
    >
    >


  8. #8
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094
    Gavin,
    Glad I could help.

    Regards,

    Steve

+ 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