Macro to sort not working on 2010 version

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have this simple sort to sort by two columns in a range,
works great but not on 2010 version,

can anyone give me a version that will work on 2010 please

heres my version
VBA Code:
Sub SortAscending1()
Application.EnableEvents = False
Application.ScreenUpdating = False

Call AA_unProtect
    ActiveSheet.Sort.SortFields.Clear
    
    
   ActiveSheet.Sort.SortFields.Add2 Key:= _
        Range("C8:C1003"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal 'its breaking here!!!!!
   ActiveSheet.Sort.SortFields.Add2 Key:= _
        Range("D8:D1003"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    With ActiveSheet.Sort
        .SetRange Range("C7:AD1003")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

ActiveSheet.Sort.SortFields.Clear

 ActiveSheet.Range("G8:G1003").Rows.AutoFit
Call AA_Protect
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

thanks

tony
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Replace all this
VBA Code:
    ActiveSheet.Sort.SortFields.Clear
    
    
   ActiveSheet.Sort.SortFields.Add2 Key:= _
        Range("C8:C1003"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal 'its breaking here!!!!!
   ActiveSheet.Sort.SortFields.Add2 Key:= _
        Range("D8:D1003"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    With ActiveSheet.Sort
        .SetRange Range("C7:AD1003")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

ActiveSheet.Sort.SortFields.Clear
with
VBA Code:
   Range("C7:AD1003").Sort Range("C7"), xlAscending, Range("D7"), , xlAscending, , , xlYes, , False
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
FYI, you could also have replaced .Add2 with .Add in your original code. ;)
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top