+ Reply to Thread
Results 1 to 11 of 11

Formula to sort columns in a spreadsheet accordingly

  1. #1
    Registered User
    Join Date
    03-29-2014
    Location
    Alabama
    MS-Off Ver
    Excel 2010
    Posts
    19

    Formula to sort columns in a spreadsheet accordingly

    I have a spreadsheet that I receive each week from the HR department that contains data about new hire employees. I have other spreadsheets that retrieve data from this new hire worksheet each week. The problem is that the person sending the spreadsheet doesn't always have the columns sorted in the same order so my formulas are all out of whack because the data isn't in the same rows. How can I setup a formula or macro that arranges all of the columns in the order that I need? I have attached an example. Thanks for your help!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Formula to sort columns in a spreadsheet accordingly

    This Macro will do that.

    sheetname must be incorrect

    Please Login or Register  to view this content.

  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,938

    Re: Formula to sort columns in a spreadsheet accordingly

    Ty this approach using regular formulas (no VBA required.

    On the sheet where you want the answers to be...
    1. copy this down in the EE ID column (B?)...
    =IFERROR(SMALL(Incorrect!D:D,ROW(A1)),"")
    2. In the other columns, use this, copied down (for all the other columns
    =IF($B2="","",INDEX(Incorrect!$A:$D,MATCH($B2,Incorrect!$D:$D,0),MATCH(A$1,Incorrect!$A$1:$D$1,0)))
    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
    03-29-2014
    Location
    Alabama
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to sort columns in a spreadsheet accordingly

    Thanks for your help Mehmetcik, this works great but suppose the columns are not always sorted in any specific order as in my 'incorrect sheet' example. Is it possible to modify this macro so that it sorts the columns to match the 'correct sheet' regardless of what order they are in? So for example, the macro should sort the columns the same regardless if the Name column is in A1, B1, C1 OR D1? Thanks again.

  5. #5
    Registered User
    Join Date
    03-29-2014
    Location
    Alabama
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to sort columns in a spreadsheet accordingly

    Quote Originally Posted by FDibbins View Post
    Ty this approach using regular formulas (no VBA required.

    On the sheet where you want the answers to be...
    1. copy this down in the EE ID column (B?)...
    =IFERROR(SMALL(Incorrect!D:D,ROW(A1)),"")
    2. In the other columns, use this, copied down (for all the other columns
    =IF($B2="","",INDEX(Incorrect!$A:$D,MATCH($B2,Incorrect!$D:$D,0),MATCH(A$1,Incorrect!$A$1:$D$1,0)))
    FDibbins, I would like to avoid VBA but I can't seem to get your formula to work. I'm sure I am doing something wrong. Here is what I get when I apply the formula:

    0 41640 0 0
    0 41641 0 0
    41642

  6. #6
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Formula to sort columns in a spreadsheet accordingly

    What is you expected results? describe it at your sample workbook


    thanks

  7. #7
    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,938

    Re: Formula to sort columns in a spreadsheet accordingly

    Take a look at the attached...
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Formula to sort columns in a spreadsheet accordingly

    LOL

    Thats exactly what I did originally.

    But that means your original file name must be fixed to.

    I will ammend it back to that version.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Formula to sort columns in a spreadsheet accordingly

    Try This:-

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Formula to sort columns in a spreadsheet accordingly

    Try This:-

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-29-2014
    Location
    Alabama
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Formula to sort columns in a spreadsheet accordingly

    Mehmetcik, this works perfectly! Thanks so much.

+ 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. Replies: 1
    Last Post: 06-10-2014, 11:13 PM
  2. Replies: 1
    Last Post: 06-10-2014, 10:45 PM
  3. [SOLVED] How do I sort or compare data from 2 different spreadsheet columns
    By bectayers in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-01-2006, 01:45 PM
  4. How to sort an Excel spreadsheet by more than 3 columns?
    By William,Summit,Oh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-28-2005, 12:35 PM
  5. Replies: 1
    Last Post: 11-27-2005, 12:15 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