+ Reply to Thread
Results 1 to 11 of 11

Sorting Merged Cells

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-01-2017
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 2013
    Posts
    148

    Sorting Merged Cells

    I'm trying to create a code that will sort a page with merged cells. I've attached an example.

    In my example I have a list of names with dates. When you press the sort button the rows will sort by Column A. I add a lot of names and as my list grows I need to keep it organized so the sort function is vital.

    On Sheet 1 you can see how the code should work. But when the list of dates gets too long I want to go to the row below and continue the dates. In these cases I want the name to merge. On Sheet two you can see how I'd like it to look with the name "Johnson, Paul". But since I have a merged cell, the sort function won't work.

    Anybody have any ideas on how to pull this off? I was thinking that it could work if Excel could somehow unmerge the merged cells, add the same name to both cells, then do the sort, then merge any cells that match in Column A. But I don't know if this id doable.

    Any help is appreciated.
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,977

    Re: Sorting Merged Cells

    Using merged cells in this way is highly inadvisable. You would be far better off just using more columns. You could write code that unmerges the merged cells, adds the same name to both cells, does the sort, then merges any cells with the same name. But using merged cells in this way is highly inadvisable. Aside from the problem you are having with merged cells, they cause a lot of other problems too.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    07-01-2017
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 2013
    Posts
    148

    Re: Sorting Merged Cells

    6StringJazzer, I think you've helped me before. So I'll trust your judgement. Its not the answer I was hoping for, but I guess I'll have to consider this option. Thank you.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,977

    Re: Sorting Merged Cells

    Quote Originally Posted by dareeldill View Post
    6StringJazzer, I think you've helped me before. So I'll trust your judgement. Its not the answer I was hoping for, but I guess I'll have to consider this option. Thank you.
    I can help with the VBA to do what you had in mind but if it were me I'd add more columns, or use a whole different setup, like one line per date repeating the person's name for each date. How are you going to use the data?

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    According to Sheet2 attachment as it is :

    PHP Code: 
    Sub SortDumbSheet()
            
    Dim Ra As RangeoCol As New CollectionV
       With ActiveSheet
    .UsedRange
         
    If Application.CountBlank(.Columns(1)) Then
            Application
    .DisplayAlerts False
            Application
    .ScreenUpdating False
           
    .Columns(1).UnMerge
            
    For Each Ra In .Columns(1).SpecialCells(4).Areas:  oCol.Add Array(Ra(0).Value2Ra.Count 1):  Ra Ra(0):  Next
           
    .Sort .Cells(1), 1Header:=1
            
    For Each V In oCol:  .Cells(Application.Match(V(0), .Columns(1), 0), 1).Resize(V(1)).Merge:  Next
            Application
    .DisplayAlerts True
            Application
    .ScreenUpdating True
         
    Else
            .
    Sort .Cells(1), 1Header:=1
         End 
    If
       
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Forum Contributor
    Join Date
    07-01-2017
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 2013
    Posts
    148

    Re: Sorting Merged Cells

    @Mark L - My real document is very very long. ATM I'm at over 2,000 rows. Thanks anyways though.

    @6StringJazzer - I can definitely add more columns. I just preferred the aesthetic appearance of keeping everything within view without having to scroll horizontally. Its easier, just not as pretty as I wanted it in my mind.

    Thank you both.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Sorting Merged Cells


    Quote Originally Posted by dareeldill View Post
    @Mark L - My real document is very very long.
    Anyway try my not too slow post #7 VBA procedure (as it depends on the number of merged areas) …

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Sorting Merged Cells


    Rather than merging cells just use Center Across Coluimns if really necessary to 'merge' cell horizontally …

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Sorting Merged Cells


    Anyway according to your Sheet2 attachment : how may rows in real ?
    'Cause I have some ways but slower that the Excel sort feature, the more rows, the slower …

  10. #10
    Forum Contributor
    Join Date
    07-01-2017
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 2013
    Posts
    148

    Re: Sorting Merged Cells

    Mark,

    I tried yours and it didn't work exactly as needed. I tried it with two people having the same name. In one situation it merged the cell below the matching names but not the matching names themselves.

    I think I'll be ok with more columns though for now.

    Thank you.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Sorting Merged Cells


    As on my side it well works with your initial post as it is, I can't reproduce any issue.

    For not smart worksheet try with CurrentRegion instead of UsedRange …

+ 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 merged cells
    By Peterino in forum Excel General
    Replies: 14
    Last Post: 11-11-2018, 02:05 AM
  2. Sorting Merged Cells in a Table
    By eazy899 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2017, 02:09 PM
  3. Sorting with merged cells
    By ruchir_shah in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-10-2016, 03:03 AM
  4. Sorting merged cells
    By lily1030 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-26-2016, 07:14 PM
  5. Help Charting and Sorting with Merged Cells
    By cherber2 in forum Excel General
    Replies: 1
    Last Post: 03-17-2014, 09:32 AM
  6. sorting merged cells
    By Bope in forum Excel General
    Replies: 0
    Last Post: 04-07-2008, 11:56 AM
  7. sorting merged cells
    By Di in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2006, 08:30 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