I have two identical macros to sort data. The only difference is which column is sorted. Both macros run correctly when run manually, but SortByDate throws an error when run from the custom button. SortByPPR works correctly. I can't see any differences in settings.
The error is: Cannot run the macro...The macro may not be available in this workbook or all macros may be disabled"
Sub SortByDate()
'
' SortByDate Macro
'
'
Range("A6:O35").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range("F6:F35") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A6:O35")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Sub SortByPPR()
'
' SortByPPR Macro
'
Range("A6:O35").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range("b6:b35") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A6:O35")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'
End Sub