+ Reply to Thread
Results 1 to 15 of 15

Sorting sets of rows based on cell

  1. #1
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Sorting sets of rows based on cell

    I need to get Excel to sort data, grouped into 4-row sets, based on a single cell in each 4-row set. Each set of 4 rows must stay grouped together when sorted (the cell that will determine the order is the designator for each set of data, basically just sequential numbers).

    If I use the standard methods which I am familiar with (such as the AutoFilter or Sort tools), it sorts each row that contains the cell I need, leaving the rest unsorted after the x number of cells have been sorted.

    Any thoughts? I don't know where to begin with the code, and the help pages I am finding just use AutoFilter.
    Last edited by mpkavanagh; 01-25-2011 at 05:09 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting sets of rows based on cell

    Hello mpkavanagh,

    Why not post a workbook with before and after examples?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    Before and after examples of what I am trying to do? I can manually manipulate the data to show what I need to have happen, but I am afraid I blanking on the code. And thanks for your quick reply.
    Last edited by mpkavanagh; 01-25-2011 at 06:13 PM.

  4. #4
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    I will give it a shot. Here goes.

    Each data set is 4 rows (Ax to Dx) and must be sorted based on cell E(3 + 4j), where j =0,1,2,3...

    Thanks again!
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    Bump. No reply.

  6. #6
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    Again. I would think this is easy, I am just missing something.

  7. #7
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    BUMP. Still looking for help.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting sets of rows based on cell

    Hello mpkavanagh,

    Thanks for posting the example. It appears that columns "A" and "B" and not part of the sort. Is this correct?

  9. #9
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    Woops. I am very sorry. The corresponding rows in columns A and B should move with the other columns. Please see attached. I have fixed that and added "1,2,3,4" to each cell of data to indicate that every cell in each 4-row set needs to be sorted, based on cell E(3 + 4j), where j =0,1,2,3...
    Attached Files Attached Files

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sorting sets of rows based on cell

    Hello mpkavanagh,

    Thanks for the updated workbook. Will the actual data numbers start at 1?

  11. #11
    Valued Forum Contributor mahju's Avatar
    Join Date
    11-27-2010
    Location
    Pakistan, Faisalabad
    MS-Off Ver
    Excel 2010 plus
    Posts
    730

    Re: Sorting sets of rows based on cell

    Hi
    i noted your cell has two parts, one is a number 1 through 4 and other alphabet A , B, C and D.
    You can split them in two separate columns and sort on these columns
    I think this should work.

    See attached sheet

    Regards
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    Quote Originally Posted by Leith Ross View Post
    Hello mpkavanagh,

    Thanks for the updated workbook. Will the actual data numbers start at 1?
    Not neccesarily. It can start at any integer and the data may not be consecutive numbers.

    Quote Originally Posted by mahju View Post
    Hi
    i noted your cell has two parts, one is a number 1 through 4 and other alphabet A , B, C and D.
    You can split them in two separate columns and sort on these columns
    I think this should work.

    See attached sheet

    Regards
    Not quite. I have re-attached another example. This time I have boxed around each data set. The entire boxed set has to be sorted among the other boxed sets based on the cell I indicated previously, and each cell of data in each set has to remain in the same relative cell location within the set. The data I presented is basically meaningless (I hope) except for the cell to be sorted. The critical part is that each distinct set needs to remain as such.

    Make sense? Is this even possible?
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    BUMP. Still looking.

  14. #14
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    Okay, using this code, I have managed to sort things using a brute force technique (I create a column and copy the cell I am using to search into the 4 rows of that column, sort using that column, then delete the column, leaving the data).

    However, I need a way to select ALL the data for the SortFields code (I recorded a macro for this code), not just the range it selects. I tested it with 12 sets of data and it gave me the range A1:H395, but I need it to work for any number of sets of data. Is there a way to reference ALL values in Columns A through H?

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Sorting sets of rows based on cell

    I think I have it. I just used the range "A1:H65536" to take care of everything. I won't be needing to sort more than a few thousand rows anyways, but I wanted to be sure nothing was missed.

    I still can't edit my old threads, so if a moderator could mark this as SOLVED, it would be greatly appreciated.

+ 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