RAYLWARD102
Well-known Member
- Joined
- May 27, 2010
- Messages
- 529
I've recorded a custom sort.
The sort works exactly how I want, when manually applied (during record process), but fails to apply when applied by executing recorded vba code; by fail, I mean not applying sort and no error messages displayed.
After the code has completed, I can visit the "Custom Sort" GUI and see my custom sort detailed in there (vba is correctly detailing my sort levels); Pressing ok from this screen, produces a sort warning to which I choose ok and then my sort actually applies.
The key piece that appears to be failing to execute, is the applying of the sort. Any idea's?
The sort works exactly how I want, when manually applied (during record process), but fails to apply when applied by executing recorded vba code; by fail, I mean not applying sort and no error messages displayed.
After the code has completed, I can visit the "Custom Sort" GUI and see my custom sort detailed in there (vba is correctly detailing my sort levels); Pressing ok from this screen, produces a sort warning to which I choose ok and then my sort actually applies.
The key piece that appears to be failing to execute, is the applying of the sort. Any idea's?
Code:
ActiveWorkbook.Worksheets("Orders").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Orders").Sort.SortFields.Add2 Key:=Range( _
"M2:M9808"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
ActiveWorkbook.Worksheets("Orders").Sort.SortFields.Add2 Key:=Range( _
"A2:A9808"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Orders").Sort.SortFields.Add2 Key:=Range( _
"E2:E9808"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Orders").Sort
.SetRange Range("A1:O9808")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With