+ Reply to Thread
Results 1 to 8 of 8

Sorting causing errors with lookups

  1. #1
    Registered User
    Join Date
    11-24-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2013
    Posts
    8

    Sorting causing errors with lookups

    My whole excel has been messed up because of sorting..
    I made some files to grab data and now when i sort names in order their grades gets messed up..
    Its grabbing wrong information for some reason\
    Example: Look at rashid khalid and his marks and his marks in english/computer/math sheet.
    Attached Files Attached Files
    Last edited by Khoori7; 11-26-2013 at 10:48 PM.

  2. #2
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.83 (24031120))
    Posts
    8,686

    Re: Sorting

    Seems for some reason the reference is not changing B6 is not changing when you sort, seems to change OK when copied

    not sure why yet
    Last edited by etaf; 11-26-2013 at 01:57 AM.
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    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,917

    Re: Sorting causing errors with lookups

    1st, change your headings to ...gradeS instead of just grade, so that they match your sheet names

    Then copy this into F2, down and across...
    =INDEX(INDIRECT("'"&F$1&"'!$E$2:$E$20"),MATCH(INDIRECT("B"&ROW()),INDIRECT("'"&F$1&"'!$A$2:$A$20"),0))

    You should now be able to sort whichever way you want

    edit: etaf, the index/match is working fine, but if you sort it, the formula doesnt move with the sort, just the reference, so it gets all messed up
    Last edited by FDibbins; 11-26-2013 at 02:06 AM.
    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

  4. #4
    Registered User
    Join Date
    11-24-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Sorting causing errors with lookups

    Quote Originally Posted by FDibbins View Post
    1st, change your headings to ...gradeS instead of just grade, so that they match your sheet names

    Then copy this into F2, down and across...
    =INDEX(INDIRECT("'"&F$1&"'!$E$2:$E$20"),MATCH(INDIRECT("B"&ROW()),INDIRECT("'"&F$1&"'!$A$2:$A$20"),0))

    You should now be able to sort whichever way you want

    edit: etaf, the index/match is working fine, but if you sort it, the formula doesnt move with the sort, just the reference, so it gets all messed up
    Hmm, didn't really understand ignore sorting then don't want that.. but why isn't this working
    =INDEX('Computer grades'!$E$2:$E$20,MATCH('Student Information'!$B15,'Computer grades'!$A$2:$A$20,0))
    it's giving me names in averages in wrong way like
    http://i.imgur.com/w1iYPfz.png
    His average comes up wrong.. from the other sheets.
    http://i.imgur.com/w1iYPfz.png

  5. #5
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.83 (24031120))
    Posts
    8,686

    Re: Sorting causing errors with lookups

    its because the reference '!$B15 is not changing the row number , when its sorted and so row 15 is referenced only , and when sorting , different names will appear in row 15 depending on the sort

    and FDibbins has provided an alternative formula

    i didnt realise that this formula does not work correctly under sort

  6. #6
    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,917

    Re: Sorting causing errors with lookups

    When you sort the names, the formula is staying in row 2, but reference to that name moves with the name. so...
    F2=INDEX('Computer grades'!$E$2:$E$20,MATCH('Student Information'!$B2,'Computer grades'!$A$2:$A$20,0))
    becomes...
    F2=INDEX('Computer grades'!$E$2:$E$20,MATCH('Student Information'!$B15,'Computer grades'!$A$2:$A$20,0))

    If you want to be able to sort the names, use the formula I gave you above. I modified it so that you can just copy it across and wont need to edit it for different sheets

  7. #7
    Registered User
    Join Date
    11-24-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Sorting causing errors with lookups

    Oh wow thanks both of you, it worked.
    I'm done with this now thanks for all your help :D

  8. #8
    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,917

    Re: Sorting causing errors with lookups

    Happy to help and thanks for the feedback

+ 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. Sorting by Date--Need help when sorting by 2-digit year
    By Farris_TN in forum Excel General
    Replies: 3
    Last Post: 06-20-2013, 11:20 AM
  2. Sorting 2 data ranges by comparing one column in each and sorting to match
    By MDKsmiffy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2013, 03:30 PM
  3. Sorting a range to invert it upside down without sorting by any specific column
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-29-2013, 12:53 PM
  4. [SOLVED] Sorting a range to invert it upside down without sorting by any specific column
    By luv2glyd in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-28-2013, 12:43 PM
  5. Sorting and Delete rows meeting criteria based on sorting criteria
    By ron2k_1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2011, 02:40 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