Hi
I guess the output you want in continuous range. If so, try this
Code:
Option Explicit
Sub SortData(ByRef Destination As Range, ParamArray SourceData())
Dim NonBlankData(), n As Long, r As Long, c As Long
Dim WholeData, i As Long
Const MaxOutputRows As Long = 1000
Const OutputColumns As Long = 12
ReDim NonBlankData(1 To MaxOutputRows, 1 To 12)
For i = LBound(SourceData) To UBound(SourceData)
WholeData = SourceData(i)
For r = 1 To UBound(WholeData, 1)
If Len(WholeData(r, 1)) Then
n = n + 1
For c = 1 To UBound(WholeData, 2)
NonBlankData(n, c) = WholeData(r, c)
Next
End If
Next
Next
If n Then
With Destination
.Resize(n, UBound(NonBlankData, 2)).Value2 = NonBlankData
With .Resize(n, UBound(NonBlankData, 2)) 'adjust the sorting columns. here it's 1,8 and 9th column of the output range
.Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Key2:=.Cells(1, 8), _
Order2:=xlDescending, Key3:=.Cells(1, 9), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End With
End With
End If
End Sub
'***** and call the procedure like this...
Sub kTest()
Dim rngDest As Range
Set rngDest = Worksheets("OSum").Range("AE102") '<< adjust the sheet name and the range
With Worksheets("OSum")
SortData rngDest, .Range("ae3:ap17").Value2, .Range("ae102:ap116").Value2, .Range("ae202:ap216").Value2 '<< add more ranges here
End With
End Sub
Bookmarks