molsonlabatt
New Member
- Joined
- Jul 25, 2012
- Messages
- 14
Hi,
I have completed my code with 2010 and have have checked it on 2007 and both work great. When I try and use it on excel 2003 I get the runtime 438 error. The error occurs (in bold) on the Sort portion of my code, shown below.
Is there anyway I can modify the code to work with excel 2003
Thanks
I have completed my code with 2010 and have have checked it on 2007 and both work great. When I try and use it on excel 2003 I get the runtime 438 error. The error occurs (in bold) on the Sort portion of my code, shown below.
Is there anyway I can modify the code to work with excel 2003
Thanks
Code:
' Gets last row number and last column number
LastRow = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ThisWorkbook.Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
' Create name for all sort area
Set SortA = ActiveSheet.Range(Cells(1, 1), Cells(LastRow, LastCol))
' Sort cells by last column
Range("A1").Select
[B]ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear[/B]
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(Worksheets("Sheet1").Cells(1, LastCol), Worksheets("Sheet1").Cells(LastRow, LastCol)), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange SortA
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With