+ Reply to Thread
Results 1 to 3 of 3

Sort sheet based on header criteria

  1. #1
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Sort sheet based on header criteria

    Hi all,

    I have a challenging task that really goes beyond my knowledge. I need code doing the following.

    Attached book has 2 sheets. Sheet 1 contains a list the way it's passed on to me. Cell E1 (highlighted just for visual purposes), comes with a different content each time. That specific content dictates how the below rows should be sorted out. All cells containing that criteria (plus any additional content) have to end in column E. Sheet 2 shows how I need the sheet to end. From sheet 1, notice row 5 has content down to column F. In that case, I need to insert a row below row 5, and move the content of E5 down to D6 and F6 to E6. Then, row 10 in Sheet 1, has content down to G10, so 2 new rows need to be inserted below it, and the content of E10 needs to be moved down to D12 & G10 down to D13, (so F10 moves to E11), as shown in Sheet 2. Notice in this row, however, F10 is the cell containing the criteria from the header but it comes first in order than G10 (since cells per row are sorted out alphabetically based on their content), therefore, it needs to end as cell E11. Row 12 in Sheet 1 is similar than row 5.

    Guess a loop that looks into the content of E1 and then reads each row to compare it is the way to go? ...

    Attached book is a sample. The lists I receive actually contain many more rows (up to a few thousands) and, in some cases, content of some rows might go down to column J. Nevertheless, cell E1 will always be the one dictating the sort. Is this even possible? ...

    Any help will be highly appreciated.

    Note: I don't need a new sheet created, I added it just to show how the list is meant to end.
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Sort sheet based on header criteria

    See the attached spreadsheet. Note that the code is hard coded for only two additional locations. Also the code refers to a source sheet (sheet with raw data) and destination sheet. It is marked clearly in the code where the sheet names need to be changed if required.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort sheet based on header criteria

    Hi,

    I truly appreciate you took the time to respond to my question.

    Thanks!

+ 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. [SOLVED] Sort table based on criteria typed in the sheet
    By brunces in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2016, 10:22 PM
  2. [SOLVED] Macro to sort sheet based on header text in Row 1
    By nyree in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-01-2015, 08:51 AM
  3. Adjusted question - Copy data to 2nd sheet based on criteria and sort
    By ALWETTA in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-02-2015, 10:55 AM
  4. Replies: 0
    Last Post: 03-01-2015, 01:56 PM
  5. [SOLVED] custom sort according to header in each sheet
    By raj soni in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 12-01-2014, 01:45 PM
  6. Copy and Paste Rows based on Criteria onto another sheet and sort based on oldest item
    By Kushal8684 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2013, 05:37 AM
  7. Sort one excel sheet into two based on territory criteria
    By VBA? in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2010, 05:47 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