SORTING MERGED CELLS BY DATE WITHOUT SEPARATING THE DATA AND CELLS." Eğer başka bir ko

suleymantaha

New Member
Joined
Sep 5, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Order No.; This line will remain fixed, and names will be included in the ranking according to their lines.
Duty Location; This line will not change.
Duty Departure; The ranking will be based on this line.
Duty Return; This line will not change.
Names; Names represent personnel who have a sequence number and have been on duty on that date.
Process to be done; I get data from two different lists like this, and when I paste them one under the other, I can't sort because there's a merged cell. I want to sort by the duty departure date without changing its content.
 

Attachments

  • Ekran Alıntısı.PNG
    Ekran Alıntısı.PNG
    24.1 KB · Views: 7

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Welcome to the Board!

This is a big problem with merged cells - using them takes away a lot of abilities, such as the ability to effectively sort, use certain VBA codes, and other features.
Merged cells cause a TON of problems with Excel, and as such, it is HIGHLY recommended that you avoid using them (most experienced programmers won't touch them with a 10 foot pole!).

Without removing them or altering your cells, I don't know that you are going to be able to do what you want.
 
Upvote 0
"Thank you very much. I know, but that's how they operate within the institution. We also send it in that format, so we can't split the cells. I haven't tried it with Python; I've tried many ways, but it doesn't work. I haven't tried exporting as a PDF either, but I'll look into that next. I appreciate the time you took to write to me.
 
Upvote 0
If you are open to using a macro you could give this a try.
I am assuming:-
• Sorting by Column D which is a date field
• Column F is not in use (I am temporarily replicating the Date field there)
VBA Code:
Sub SortMergedData()

    Dim ws As Worksheet
    Dim rngMerged As Range, rngDetail As Range
    Dim arrMerged As Variant, arrDetail As Variant
    Dim lngDetDt As Long
    Dim rowLast As Long, i As Long
    
    Application.ScreenUpdating = False
    
    Set ws = ActiveSheet
    rowLast = ws.Range("E" & Rows.Count).End(xlUp).Row
    Set rngDetail = ws.Range("E2:E" & rowLast)
    arrDetail = rngDetail.Resize(, 2)
    Set rngMerged = ws.Range("A2:D" & rowLast)
    arrMerged = rngMerged.Value2
    
    For i = 1 To UBound(arrDetail)
        If arrMerged(i, 4) <> "" Then
            lngDetDt = arrMerged(i, 4)
        End If
        arrDetail(i, 2) = lngDetDt
    Next i
    
    rngDetail.Offset(, 1) = Application.Index(arrDetail, 0, 2)
    
    rngMerged.Sort Key1:=Range("D2"), _
                     Order1:=xlAscending, _
                     Header:=xlNo
    rngDetail.Resize(, 2).Sort Key1:=Range("F2"), _
                     Order1:=xlAscending, _
                     Header:=xlNo
                     
    rngDetail.Offset(, 1).ClearContents
    
    Application.ScreenUpdating = True
                     
                     
End Sub

My test data in case anyone else want to have a go was:
20230905 VBA Sort Merged Cells suleymantaha.xlsm
ABCDE
1Order NoDuty LocationDuty DepartureDuty ReturnNames
23Loc3Dept 35/09/2023Name 3 1
3Name 3 2
4Name 3 3
5Name 3 4
6Name 3 5
72Loc2Dept 220/08/2023Name 2 1
8Name 2 2
9Name 2 3
10Name 2 4
11Name 2 5
121Loc1Dept 115/08/2023Name 1 1
13Name 1 2
14Name 1 3
15Name 1 4
16Name 1 5
Data
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top