+ Reply to Thread
Results 1 to 14 of 14

Sorting multiple columns with lookup values

  1. #1
    Registered User
    Join Date
    02-25-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    4

    Sorting multiple columns with lookup values

    (Lookup values are when a cell contains "=B4" correct?)

    I have three columns: A has names, B has lookup values, C has lookup values as well. I want to be able to sort Column B from largest to smallest. I need to keep the rows together that correspond with values in Column B. And if there's a way to have Column C's values be the tiebreaker if Column B's values are the same that would be great! If not, then they do not have to be in any order. If I try Data->Sort I get a bunch of errors since they're all lookup values. I used a formula a long time ago that sorted this but I've long since forgot it.

    I have a simple example as the attachment.

    Any help is appreciated!
    Attached Files Attached Files

  2. #2
    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
    44,445

    Re: Sorting multiple columns with lookup values

    No, they're not lookup formulae, they're simple links to cells. You need to use VLOOKUP with the name as the key (search item) and columns F, G and H as the lookup table.

    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


  3. #3
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Sorting multiple columns with lookup values

    Well, this solution is by no means perfect, but I have to run and my mind is drawing a blank. See the attachment that uses a helper row to achieve the sort. This is limited by names being unique within the first three characters. Let me know what you think. Thanks!
    Attached Files Attached Files
    -Greg If this is helpful, pls click Star icon in lower left corner

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Sorting multiple columns with lookup values

    1st, absolute your references in col A ($F$2), then change the formula in col B and col C to

    =VLOOKUP(A2,$F$2:$H$5,2,FALSE) and =VLOOKUP(A2,$F$2:$H$5,3,FALSE)

    To sort the way you want, use...

    data/sort/select col B as 1st sort/add level/select col C as 2nd sort

    I think this will give you what you want, play around with it some
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Sorting multiple columns with lookup values

    another method would be to 'rank' each score and do a look up on that, i did this in the attached by creating a unique value for each person by adding B as a whoel and C/1000 (to use as a tie break) and adding a random fractional number to break final ties.

    this will automaticaly 'sort' every time the data is updated.

    the example attached should make this clearer, with the added columns in yellow, and modified cells in blue
    Attached Files Attached Files
    Last edited by DGagnon; 02-25-2012 at 07:59 PM. Reason: typo
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  6. #6
    Registered User
    Join Date
    02-25-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Sorting multiple columns with lookup values

    Thanks for the responses guys!
    @TMShucks, tried doing something with =vlookup and then rank but if the ranks were the same I'd get a bunch of errors. Nice to know that function!
    @gjlindn I see a huge number in the helper row and I don't get how this sorts things...
    @FDibbins PERFECT! Exactly what I needed.
    @DGagnon this works as well! I think this is what gjlindn was trying to show me.

    Thanks everyone for the help and new knowledge! Appreciate it.

  7. #7
    Registered User
    Join Date
    02-25-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Sorting multiple columns with lookup values

    EDIT - figured it out
    Attached Files Attached Files
    Last edited by eltharion; 02-25-2012 at 08:43 PM.

  8. #8
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Sorting multiple columns with lookup values

    i think you may have attached the wrong sheet, there is only data in one sheet.

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Sorting multiple columns with lookup values

    You attached the same workbook as before, maybe you didnt upload the new sheet?

  10. #10
    Registered User
    Join Date
    02-25-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Sorting multiple columns with lookup values

    Yes yes, I noticed that and when I went to type it out again (forgot to save!) it worked.

    Now the only problem is after sorting, it doesn't sort when the numbers are updated. DGagnon's method looks to autosort, is there a way I can use FDibbin's and have it autosort?

  11. #11
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Sorting multiple columns with lookup values

    when using the sort option there is no way to automate it on a change, that is why my method requires the 'Rank' columns.

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Sorting multiple columns with lookup values

    You can either use the code below, copy it into a module, or use macro record (to the right of the "ready" icon) and make your own in the "real" workbook. Then add a button (Insert shape - pick what you want) and assign the macro to it (right click/assign macro). This way, with 1 click, you can update your sort whenever you want

    Hope this helps

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Sorting multiple columns with lookup values

    oops forgot to add the code...
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Sorting multiple columns with lookup values

    Hi eltharion...in my haste earlier I neglected to add the decimal point in the helper formula. This example is working correctly. This method does not require manually sorting or sorting by vba macro, but automatically sorts the data in columns A, B & C by updating the data in columns F, G & H. Limitations of this process are column G cannot exceed max value of 9 and names must be unique after 3 characters (although this could be increased by adding more CODE/MID. formulas). I'm not suggesting you use this vs. one of the other memebers methods, but I wanted to correct my error and show you how this works. Thanks!
    Attached Files Attached Files

+ 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