View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Modify Claus code "Sub Array_Var_Column_Sort()"

Hi Howard,

Am Thu, 21 Aug 2014 22:53:16 -0700 (PDT) schrieb L. Howard:

I tried this, which put i to 1 (one) in the code line, but still errors out.


try:

Sub Array_Var_Column_Sort()
'/ Claus

Dim LRow As Range
Dim Lcol As Long
Dim i As Long
Dim varKey As Variant

Application.ScreenUpdating = False

With Sheets("sheet1")

'Last column
Lcol = .Cells(1, Columns.Count).End(xlToLeft).Column

'LCol is not needed because you sort each column in a seperate loop.
'If you look for last column you have to use xlToLeft and NOT xlUp

'Sortkeys
varKey = Array("A1", "C1", "E1")
.Sort.SortFields.Clear
For i = LBound(varKey) To UBound(varKey)
Set LRow = .Cells(Rows.Count, Asc(Left(varKey(i), 1)) -
64).End(xlUp)
.Range(varKey(i), LRow).Sort _
Key1:=.Range(varKey(i)), order1:=xlDescending, Header:=xlNo
'Header:=xlYes
Next
'
End With
Application.ScreenUpdating = True
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional