Hello,

I have a macro that works 75% of the time. I can't determine why it doesn't work all the time. It works with varied number of records. The code always fails during the sorting of columns at 'ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Clear'. I don't believe this is the line actually causing the error, but I have to admit I have no clue.

'Find the last used row in a Column: column A in this example
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

'Find the last used column in a Row: row 1 in this example
Dim LastCol As Integer
With ActiveSheet
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With

'Sort Group/Suffix, Subscriber, Member Last, Member First
Cells.Select
ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Add Key _
:=Range("A2:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortTextAsNumbers
ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Add Key _
:=Range("B2:B" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Add Key _
:=Range("E2:E" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Add Key _
:=Range("P2:P" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(sfilename).Sort.SortFields.Add Key _
:=Range("Q2:Q" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(sfilename).Sort
.SetRange Range("A1:Y" & LastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Thanks for your help!!!