Sort not working

liampog

Active Member
Joined
Aug 3, 2010
Messages
316
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all

Can anyone tell me why this code doesn't work in Excel 2003?

Code:
    If Not Intersect(Target, Range("A3:D1002")) Is Nothing Then
        ActiveSheet.Unprotect
        Application.EnableEvents = False
        If Len(Range("A" & Target.Row).Value) * Len(Range("B" & Target.Row).Value) * Len(Range("C" & Target.Row).Value) > 0 Or Len(Range("A" & Target.Row).Value) + Len(Range("B" & Target.Row).Value) + Len(Range("C" & Target.Row).Value) + Len(Range("D" & Target.Row).Value) = 0 Then
            ActiveSheet.Sort.SortFields.Clear
            ActiveSheet.Sort.SortFields.Add Key:=Range("B3:B1002"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            ActiveSheet.Sort.SortFields.Add Key:=Range("A3:A1002"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            ActiveSheet.Sort.SortFields.Add Key:=Range("D3:D1002"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            With ActiveSheet.Sort
                .SetRange Range("A3:E1002")
                .Header = xlGuess
                .MatchCase = False
                .Orientation = xlTopToBottom
                .SortMethod = xlPinYin
                .Apply
            End With
        End If
        Application.EnableEvents = True
        ActiveSheet.Protect
    End If
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Because it is using the sort method introduced in Excel 2007.

If you record a macro whilst sorting manually it will give you the syntax for Excel 2003.
 
Upvote 0
I don't really want to record a macro because it includes all kinds of useless code. Can anyone provide a 2003 solution that does the same as the code I provided?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

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