A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Not clear if you want to sort the four data sets "independent" of each other or if data should be moved "between" the data sets.
Assuming that no data should be moved between the data sets and that all data sets should be sorted by the first column, try this macro:
Sub sort_4_ranges()
Dim ws As Worksheet
Dim first_cell As Range
Dim next_cell As Range
Set ws = ActiveWorkbook.Worksheets("Sheet6") 'change name
columns_to_sort = 10 'change to suit your data
Set first_cell = ws.Range("E10") 'the first cell of the first data set to sort
sorted_datasets = 0
While sorted_datasets < 4
Set next_cell = first_cell
While next_cell.MergeArea.Count = 1
Set next_cell = next_cell.Offset(1, 0)
Wend
'sorting code
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add Key:=Range(first_cell.Address), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
With ws.Sort
.SetRange Range(first_cell.Address & ":" & next_cell.Offset(-1, columns_to_sort).Address)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Set first_cell = next_cell.Offset(1, 0) 'change the 1 if the next data set it not immediately after the row with merged cells
sorted_datasets = sorted_datasets + 1
Wend
End Sub
If the data should be sorted by some other column than the first column, change
Key:=Range(first_cell.Address)
to
Key:=Range(first_cell.Offset(0,column_to_sort_by-1).Address)
Hope this helps / Lars-Åke