Applying Variables to SORT
Hi,
Am Mon, 11 Aug 2014 07:51:13 -0700 (PDT) schrieb sylink:
I guess the following need to be modified to accept variable number of records :Range("A2:A7746"), Range("F2:F7746"),Range("I2:I7746"), Range("A1:X7746")
is that what you need?
Sub Test()
Dim LRow As Long, LCol As Long, i As Long
Dim varKey As Variant
Application.ScreenUpdating = False
With Sheets("sectxW")
'Last row
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
'Last column
LCol = .Cells(1, Columns.Count).End(xlUp).Column
'Sortkeys
varKey = Array("A1", "F1", "I1")
.Sort.SortFields.Clear
For i = LBound(varKey) To UBound(varKey)
.Range(.Cells(1, 1), .Cells(LRow, LCol)).Sort _
Key1:=.Range(varKey(i)), order1:=xlAscending, Header:=xlYes
Next
End With
Application.ScreenUpdating = True
End Sub
Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
|