+ Reply to Thread
Results 1 to 10 of 10

Solved: Formula to total # of cells based on criteria

  1. #1
    Registered User
    Join Date
    03-14-2010
    Location
    Jersey
    MS-Off Ver
    Excel 2003
    Posts
    30

    Solved: Formula to total # of cells based on criteria

    I am trying to figure out a formula that will give me the total count of cells to match my criteria below:

    Criteria:
    Is the first Non-Rotational Location in the same state as the University?
    If so, how many are there?

    The state (spelled out completely) of each location is in the "Location" Tab
    The location list will be a dynamic list.

    I would like a formula that can find the state for each 1st Non-Rotational Location shown above and then see if it is the same as the "State of University" of the cell next to it.
    If it is a match, it should count it and provide a sum of the total matches.
    Attached Files Attached Files
    Last edited by bbarrene; 02-28-2011 at 01:54 PM.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Formula to total # of cells based on criteria

    First, change your dynamic range "Location" to be 2 columns wide (change the last "1" to a 2).

    In G2 dragged down
    =IF(VLOOKUP(E2,Location,2,FALSE)=Table!A2,SUMPRODUCT(--($E$2:$E$21=E2),--($A$2:$A$21=A2)),"NO")
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    03-14-2010
    Location
    Jersey
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Formula to total # of cells based on criteria

    Quote Originally Posted by ChemistB View Post
    First, change your dynamic range "Location" to be 2 columns wide (change the last "1" to a 2).

    In G2 dragged down
    =IF(VLOOKUP(E2,Location,2,FALSE)=Table!A2,SUMPRODUCT(--($E$2:$E$21=E2),--($A$2:$A$21=A2)),"NO")
    Does that work for you?
    Not quite but close. I just want one cell to show the total amount of matches. Is there a way to have the formula of one cell scan through the list of "1st Non Rotational Locations", determine the state of the location, and see if the University State matches it.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Formula to total # of cells based on criteria

    Question: When you have duplicates (i.e. you have two "Utah- Sandy Ut entries) do they count as 1 or 2?

  5. #5
    Registered User
    Join Date
    03-14-2010
    Location
    Jersey
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Formula to total # of cells based on criteria

    Quote Originally Posted by ChemistB View Post
    Question: When you have duplicates (i.e. you have two "Utah- Sandy Ut entries) do they count as 1 or 2?
    They count as two. The list is basically showing the school a person attended and next to that, it shows the location of the first position they were assigned.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Formula to total # of cells based on criteria

    I couldn't come up with a way without dummy columns. In G2 dragged down

    =VLOOKUP(E2,Location,2,0)=A2 (You can hide that column if you like)

    In H2
    =COUNTIF(G2:G21,TRUE)
    Does that work for you?

  7. #7
    Registered User
    Join Date
    03-14-2010
    Location
    Jersey
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Formula to total # of cells based on criteria

    Quote Originally Posted by ChemistB View Post
    I couldn't come up with a way without dummy columns. In G2 dragged down

    =VLOOKUP(E2,Location,2,0)=A2 (You can hide that column if you like)

    In H2
    =COUNTIF(G2:G21,TRUE)
    Does that work for you?
    Yea, I came up with that solution as well. I was hoping that could be avoided but I guess not. Thanks for the help.

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Formula to total # of cells based on criteria

    As per Daddy LongLegs;

    =SUM(IF(ISNA(LOOKUP(E2:E21,Location)),"",IF((LOOKUP(E2:E21,Location)=A2:A21)*(COUNTIF(INDEX(Location ,0,1),E2:E21)),1)))
    entered as an array (CNTRL + SHFT + ENTER).

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

    Re: Formula to total # of cells based on criteria

    ....thanks ChemistB, I also realised that could be simplified a little, i.e.

    =SUM(IF(COUNTIF(INDEX(Location,0,1),E2:E21),IF(LOOKUP(E2:E21,Location)=A2:A21,1)))

    confirmed with CTRL+SHIFT+ENTER

    The lookup range (1st column of location) needs to be sorted ascending
    Audere est facere

  10. #10
    Registered User
    Join Date
    03-14-2010
    Location
    Jersey
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Formula to total # of cells based on criteria

    Quote Originally Posted by ChemistB View Post
    As per Daddy LongLegs;

    =SUM(IF(ISNA(LOOKUP(E2:E21,Location)),"",IF((LOOKUP(E2:E21,Location)=A2:A21)*(COUNTIF(INDEX(Location ,0,1),E2:E21)),1)))
    entered as an array (CNTRL + SHFT + ENTER).
    Quote Originally Posted by daddylonglegs View Post
    ....thanks ChemistB, I also realised that could be simplified a little, i.e.

    =SUM(IF(COUNTIF(INDEX(Location,0,1),E2:E21),IF(LOOKUP(E2:E21,Location)=A2:A21,1)))

    confirmed with CTRL+SHIFT+ENTER

    The lookup range (1st column of location) needs to be sorted ascending

    Thanks for the help. Props go out to you.
    Last edited by bbarrene; 02-28-2011 at 01:55 PM.

+ 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