To delete duplicate rows and rearrange the data in the way you described, you can use the following VBA code:
Sub RemoveDuplicatesAndSort() Dim ws As Worksheet Dim lRow As Long Dim i As Long Dim j As Long Dim temp As String Set ws = ThisWorkbook.Sheets("Sheet1") ' change "Sheet1" to your sheet name lRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' get the last row in column A ' loop through rows and delete duplicates For i = lRow To 2 Step -1 temp = ws.Cells(i, "A").Value & ws.Cells(i, "B").Value For j = i - 1 To 2 Step -1 If ws.Cells(j, "A").Value & ws.Cells(j, "B").Value = temp Then ws.Rows(j).Delete End If Next j Next i ' sort the data by column A and then column B ws.Range("A2:B" & lRow).Sort Key1:=ws.Range("A2"), Order1:=xlAscending, _ Key2:=ws.Range("B2"), Order2:=xlAscending, Header:=xlNo End Sub
To use this code, copy and paste it into the VBA editor and then run it by pressing the "Run" button or by pressing F5. Make sure to change the sheet name in line 6 to the name of the sheet where your data is located.
I hope this helps! Let me know if you have any questions.