Oh, I was using the CELL function as mentioned here, confusing myself, hah. I used your range example with Cells() function now as I already defined LastCol.
The macro now works as intended. Here is the final code for anyone else who may want to reference the working generic sort macro:
Sub GenericSort3ThruX()
'
' GenericSort3ThruX Macro
'
'
Dim LastRow As Long
With ActiveSheet.UsedRange
LastRow = .Rows(.Rows.Count).Row
LastCol = .Columns(.Columns.Count).Column
End With
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range(Cells(3, 1), Cells(LastRow, LastCol))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Again, this code ignores the first two rows, which I use as headers on my sheets. If you would want to use this code and start on a different row, you could simply change the range lines to where you please, those lines being
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A3"), _
.SetRange Range(Cells(3, 1), Cells(LastRow, LastCol))
Once again you walked me through one of my issues, Alf. Thank you for the help, I appreciate it =).
-S
Bookmarks