L
L. Howard
This seems to work but I don't trust my judgment on evaluating the outcome.
Trying to apply the row count of each variable length column to the specific column to sort.
Lrow1, 2, 3 show correct row numbers in varRow = Array(LRow1, LRow2, LRow3)
Using A1, C1 & E1 pulled down to various row lengths for testing.
I have gotten a 6 row gap in the sort in column A once in awhile.
Thanks.
Howard
Sub Array_Var_Column_Sort()
Dim LRow1 As Long, LRow2 As Long, LRow3 As Long
Dim LRowX As Long, LCol As Long
Dim i As Long, ii As Long
Dim varKey As Variant
Dim varRow As Variant
Application.ScreenUpdating = False
With Sheets("sheet5")
'Last rows
LRow1 = .Cells(Rows.Count, 1).End(xlUp).Row
LRow2 = .Cells(Rows.Count, 3).End(xlUp).Row
LRow3 = .Cells(Rows.Count, 5).End(xlUp).Row
'Last column
'LCol = .Cells(1, Columns.Count).End(xlLeft).Column
LCol = Cells.Find(What:="*", After:=[a1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
'Sortkeys
varKey = Array("A1", "C1", "E1")
varRow = Array(LRow1, LRow2, LRow3)
.Sort.SortFields.Clear
For i = LBound(varKey) To UBound(varKey)
For ii = LBound(varRow) To UBound(varRow)
.Range(.Cells(1, 1), .Cells(varRow(ii), LCol)).Sort _
Key1:=.Range(varKey(i)), order1:=xlAscending, Header:=xlNo 'Header:=xlYes
Next
Next
End With
Application.ScreenUpdating = True
End Sub
Trying to apply the row count of each variable length column to the specific column to sort.
Lrow1, 2, 3 show correct row numbers in varRow = Array(LRow1, LRow2, LRow3)
Using A1, C1 & E1 pulled down to various row lengths for testing.
I have gotten a 6 row gap in the sort in column A once in awhile.
Thanks.
Howard
Sub Array_Var_Column_Sort()
Dim LRow1 As Long, LRow2 As Long, LRow3 As Long
Dim LRowX As Long, LCol As Long
Dim i As Long, ii As Long
Dim varKey As Variant
Dim varRow As Variant
Application.ScreenUpdating = False
With Sheets("sheet5")
'Last rows
LRow1 = .Cells(Rows.Count, 1).End(xlUp).Row
LRow2 = .Cells(Rows.Count, 3).End(xlUp).Row
LRow3 = .Cells(Rows.Count, 5).End(xlUp).Row
'Last column
'LCol = .Cells(1, Columns.Count).End(xlLeft).Column
LCol = Cells.Find(What:="*", After:=[a1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
'Sortkeys
varKey = Array("A1", "C1", "E1")
varRow = Array(LRow1, LRow2, LRow3)
.Sort.SortFields.Clear
For i = LBound(varKey) To UBound(varKey)
For ii = LBound(varRow) To UBound(varRow)
.Range(.Cells(1, 1), .Cells(varRow(ii), LCol)).Sort _
Key1:=.Range(varKey(i)), order1:=xlAscending, Header:=xlNo 'Header:=xlYes
Next
Next
End With
Application.ScreenUpdating = True
End Sub