+ Reply to Thread
Results 1 to 9 of 9

SUMIF condition refers to a cell

  1. #1
    Registered User
    Join Date
    03-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Excel 2010
    Posts
    5

    SUMIF condition refers to a cell

    I have this data


    A B
    cat 3
    dog 4
    mouse 3
    fish 12
    dog 4
    cat 3
    fish 12
    turnip 27
    centipede 100
    centipede 100


    Ihave named the text list "animals" and the number list "legs"

    This formula works: sumif(animals,"=dog",legs) it returns 8

    If I put the word dog in cell G5: Can I refer to it in the formula (e.g. =sumif(animals,"=$g$5",legs) --- that doesn't work but can I change the syntax to make it work?

    Thanks

  2. #2
    Registered User
    Join Date
    03-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: SUMIF condition refers to a cell

    Sorry about the formatting but I think you can tell what I meant!

  3. #3
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: SUMIF condition refers to a cell

    Simply use

    =sumif(animals,G5,legs)

    without the "=" and quotes
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,517

    Re: SUMIF condition refers to a cell

    =SUMIF(animals,D4,legs)

    If it is just "equals" you don't actually need the equals sign.

    =SUMIF(animals,"dog",legs is the same as =SUMIF(animals,"=dog",legs)

    You could write it as =SUMIF(animals,"="&D4,legs) but there's no advantage.

    You would use it, for example, if you wanted a not equal condition: =SUMIF(animals,"<>"&D4,legs)


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    03-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: SUMIF condition refers to a cell

    Thanks all

    Can I complicate it slightly

    Suppose I wanted a wildcard in the reference cell e.g. not dog but effectively do*, is there a way to do that?

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,736

    Re: SUMIF condition refers to a cell

    With the criterion in the formula you can use

    =SUMIF(animals,"do*",legs)

    or if "do" (without quotes) is in cell G5 that can be

    =SUMIF(animals,G5&"*",legs)

    ...or with "do*" in G5 you can just use

    =SUMIF(animals,G5,legs)
    Audere est facere

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,517

    Re: SUMIF condition refers to a cell

    =SUMIF(animals,"=do*",legs)
    =SUMIF(animals,"do*",legs)
    =SUMIF(animals,C2&"*",legs)
    =SUMIF(animals,"="&C2&"*",legs)


    Regards, TMS

  8. #8
    Registered User
    Join Date
    03-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: SUMIF condition refers to a cell

    Brilliant - Thanks!!!

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,517

    Re: SUMIF condition refers to a cell

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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