+ Reply to Thread
Results 1 to 9 of 9

Returning the Highest Value in a Range with Text Criteria

  1. #1
    Registered User
    Join Date
    11-05-2009
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    32

    Returning the Highest Value in a Range with Text Criteria

    I am trying to figure out a formula that will return the highest value in a range if the corresponding cell is a certain text.

    It looks like this

    A B
    91 FB
    82 CH
    79 CH
    89 FB
    77 CH
    83 CH
    90 FB

    So I named the whole range Pitcher1 and tried this formula “=VLOOKUP("CH", MAX(PITCHER1), 3, FALSE)”, but I am getting N/A back… I have tried IF before VLOOKUP as well and that isn't working...

    please help!!!

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Returning the Highest Value in a Range with Text Criteria

    One approach

    =MAX(IF(B1:B7="CH",A1:A7))
    confirmed with CTRL + SHIFT + ENTER

  3. #3
    Registered User
    Join Date
    11-05-2009
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Returning the Highest Value in a Range with Text Criteria

    I have one to returns the text value for the maximum numeric value
    =VLOOKUP(MAX(B:B),B:C,2,FALSE)

    however, it's not working when I want to get the max numeric value for the corresponding text value

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Returning the Highest Value in a Range with Text Criteria

    equivalent: =MAX(--(B1:B7="CH")*A1:A7) Also an array function

    and the NON array function

    =SUMPRODUCT(MAX(--(B1:B7="CH")*A1:A7))
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  5. #5
    Registered User
    Join Date
    11-05-2009
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Returning the Highest Value in a Range with Text Criteria

    AWESOME! Thanks for the help and quick reply...

    why does CTR+SHFT+ENTER have to make it work?

  6. #6
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Returning the Highest Value in a Range with Text Criteria

    I have one to returns the text value for the maximum numeric value
    =VLOOKUP(MAX(B:B),B:C,2,FALSE)

    however, it's not working when I want to get the max numeric value for the corresponding text value
    =MAX(B:B) In both your and my formula the ="CH" criterium is lost ?

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Returning the Highest Value in a Range with Text Criteria

    Re: Ctrl + Shift + Enter ... makes the formula an "Array Formula"

    http://www.cpearson.com/excel/ArrayFormulas.aspx
    http://office.microsoft.com/en-us/ex...872901033.aspx

    also see link in my sig. to Colin Legg's extensive tutorial.

    @Ricardo... re: SUMPRODUCT... I confess I prefer the IF based approach myself given the same approach would be hard to apply for the MIN equivalent...
    (whereas the more traditional Array can simply revert to MIN from MAX by changing the function name)

    If you wanted to avoid the Array entry you could embed an INDEX:

    =MAX(INDEX(IF($B$1:$B$7="CH",$A$1:$A$7),0))
    confirmed with Enter

    Over large datasets the embedded INDEX would likely perform slower (so I'm led to believe by those "in the know")

  8. #8
    Registered User
    Join Date
    11-05-2009
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Returning the Highest Value in a Range with Text Criteria

    sounds good. I've only used array's in a limited amount... but speaking of them, I think I need to write another one...

    Using the same sort of data below:

    Col A Col B
    88 FB
    88 FB
    89 FB
    91 FB
    81 CH
    81 CH
    88 FB

    I'd like to be able to count the total number of FB's at 88, 89, etc - and the total number of CH at each number.

    these would all go in different cells looking like
    total
    FB #
    3 88

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Returning the Highest Value in a Range with Text Criteria

    Given use of XL2007 you should check out the COUNTIFS function in XL Help... it is unfortunate that MS do not offer the same functionality in 2007 for MIN/MAX as they do COUNT, SUM & AVERAGE (hence the need for Arrays).

    However, if your intention is to have a table listing the various combinations of Col A & Col B and their frequency you would probably be best served long term using a Pivot Table - more efficient and requires no formula knowledge per se.
    For a basic setup you could have Col A as Row Label and Col B as Column Label, add Col B again but as Data Field (should default to Count) .. you can move the fields around to get different layouts.
    (for a general intro. to PT's see link in sig. - note you will need column header values for a Pivot Table - eg A1/B1 must be field names)
    Last edited by DonkeyOte; 03-05-2010 at 01:03 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