Your code leaves the autofilter in place when either of the 2 routines runs.
This means next time a routine is run the Autofilter command actually removes the autofilter which is why the clearing of the sort fails.
You need to test for the autofilter being present are applying if not.
Range("A6:D6").Select
Range("D6").Activate
' check auto filter status
If Not ActiveSheet.AutoFilterMode Then Selection.AutoFilter
ActiveWorkbook.Worksheets("excel").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("excel").AutoFilter.Sort.SortFields.Add Key:=Range( _
"C6"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("excel").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Both routines will need the additional code.
Bookmarks