+ Reply to Thread
Results 1 to 17 of 17

Lookup returning results in alphabetical order

  1. #1
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    812

    Lookup returning results in alphabetical order

    Hi,

    I have data arranged as shown in columns A and B in the attached file.

    I would like to create a formula in D2, which will be copied down the column, that will report the product names shown in column A, if they are listed as Grade1 in column B, in alphabetical order.

    Can someone please suggest a formula that will accomplish this? (I would prefer to use a formula rather than a pivot table or filtering).

    Thanks
    Attached Files Attached Files
    Last edited by andrewc; 11-26-2013 at 06:51 AM.

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Lookup returning results in alphabetical order

    Hi

    1 way could be using this ARRAY formula in D2 and copy down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    -- Array(CSE) { }, formulae are confirmed with Control+Shift+Enter.
    Not just Enter.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Lookup returning results in alphabetical order

    Another array formula with slight variation is as follows.......

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    812

    Re: Lookup returning results in alphabetical order

    Perfect, thank you

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Lookup returning results in alphabetical order

    Best I can come up with:
    =IF(SMALL(IF($B$2:$B$7="Grade1",COUNTIF($A$2:$A$7,"<"&A$2:A$7),100),ROW(A1))=100,"",INDEX(A$2:A$7,MATCH(SMALL(IF($B$2:$B$7="Grade1",COUNTIF($A$2:$A$7,"<"&A$2:A$7),100),ROW(A1)),COUNTIF($A$2:$A$7,"<"&A$2:A$7),0)))
    in C2 as array formula and copy down
    Last edited by ragulduy; 11-26-2013 at 07:14 AM.

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Lookup returning results in alphabetical order

    You are welcome and thanks for the feedback & rep.

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Lookup returning results in alphabetical order

    Fotis/sktneer:

    your formula's don't seem to work if I swap the order in column A
    i.e. they seem to need the data to be sorted alphabetically in the first place.

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Lookup returning results in alphabetical order

    Quote Originally Posted by yudlugar View Post
    Fotis/sktneer:

    your formula's don't seem to work if I swap the order in column A
    i.e. they seem to need the data to be sorted alphabetically in the first place.
    That's true. This is the disadvantage of our formulas! Yours has other(s).

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Lookup returning results in alphabetical order

    @Fotis - it would helpful if you could provide some pointers to the disadvantages of how I did it - always looking to learn with this formula business!

  10. #10
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Lookup returning results in alphabetical order

    Sure my friend! Here one.

    Try to type twice(more than once in any way) a name in the range. In both of these type crade1 in column B. See the results!

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Lookup returning results in alphabetical order

    Ah ok, it would return duplicates values, not unique ones you mean?

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

    Re: Lookup returning results in alphabetical order

    Using ROW(A1) as an incrementer leaves the formula vulnerable to new row insertions.

    If you were to insert a new row 1 then ROW(A1) becomes ROW(A2) and could lead to incorrect results.

    A better way is to use the ROWS function. ROWS(A$1:A1)

    If a new row 1 is inserted then ROWS(A$1:A1) becomes ROWS(A$2:A2) but it still evaluates to 1 and will return the correct result.

    Using the ROWS function adds some robustness without adding inefficiency or unnecessary complexity.

    Also, it's better to use the cell address of the cell that contains the formula. This is mostly to reduce confusion. If the formula is entered in cell X27, some folks may see the reference to cell A$1 and wonder what that reference has to do with things.

    ROWS(X$27:X27)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  13. #13
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Lookup returning results in alphabetical order

    Quote Originally Posted by yudlugar View Post
    Ah ok, it would return duplicates values, not unique ones you mean?
    Exactly! ................

  14. #14
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Lookup returning results in alphabetical order

    Quote Originally Posted by Tony Valko View Post

    If a new row 1 is inserted then ROWS(A$1:A1) becomes ROWS(A$2:A2) but it still evaluates to 1 and will return the correct result.
    If I am not wrong ROWS(A$1:A1) becomes ROWS(A$1:A2).

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

    Re: Lookup returning results in alphabetical order

    Try it and see what happens.

    Enter this formula in cell A1:

    =ROWS(A$1:A1)

    The formula returns 1.

    Now, insert a new row 1.

    The formula is moved down to cell A2 and becomes =ROWS(A$2:A2) and still returns the correct result of 1.

  16. #16
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Lookup returning results in alphabetical order

    Oh yes, you are correct. I didn't consider the inserting a new row1, instead I thought it was being copied down.

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

    Re: Lookup returning results in alphabetical order

    Yes, it is being copied down a column but I was trying to demonstrate how inserting new rows can lead to incorrect results if using ROW(A1) rather than ROWS(A$1:A1).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Lookup on 1 criteria but returning multiple results
    By swingding in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-08-2013, 05:18 AM
  2. Lookup not returning expected results
    By syphlix in forum Excel General
    Replies: 4
    Last Post: 03-08-2011, 04:16 PM
  3. Returning multiple results for one lookup value
    By Lizzietish11 in forum Excel General
    Replies: 5
    Last Post: 01-29-2009, 03:09 PM
  4. Lookup Returning Multiple Results
    By joe1182 in forum Excel General
    Replies: 4
    Last Post: 02-01-2006, 08:02 AM
  5. [SOLVED] Filesearch returning files not in alphabetical order?
    By General in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-23-2005, 04:06 PM

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