Hi snapfade,
Here's a proposal. Copy the data to a temp sheet, sort in this temp sheet and then copy the sorted rows in your destination sheet.
Finally, sort the table in the destination sheet (no empty rows to consider)
Sub GetData2()
Dim ws As Worksheet
Dim wsD As Worksheet 'destination
Dim wsT As Worksheet 'temp sheet
Dim rg As Range
Dim i As Integer
Dim SheetsNames
SheetsNames = "One,Two,Three" 'List of sheets to copy from
Set wsD = Sheets("Four") 'destination
Set wsT = ThisWorkbook.Sheets.Add 'add temp sheets
'Copy column A to temp sheet
SheetsNames = Split(SheetsNames, ",")
For i = LBound(SheetsNames) To UBound(SheetsNames)
With Sheets(SheetsNames(i))
.Range("A2", .Cells(.Rows.Count, 1).End(xlUp)).Copy wsT.Cells(wsT.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
Next i
'Sort values in temp sheet
With wsT
Set rg = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp))
With .Sort
.SortFields.Add Key:=rg, SortOn:=xlSortOnValues, Order:=xlAscending
.SetRange rg
.Header = xlNo
.SortMethod = xlPinYin
.Apply
End With
.Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Copy wsD.Cells(wsD.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
' Delete Temp sheet
Application.DisplayAlerts = False
wsT.Delete
Application.DisplayAlerts = True
'Sort the destination worksheet
With wsD
With .ListObjects("tblFour").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("tblFour[Column1]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End Sub
Bookmarks