acdecal
asked on
VBA Excel sort/ range Error with 2016
Since migrating from Excel 2010 to 2016, the code below now produces an error: Method sort of object range failed. Used to work fine. Can someone please help with this?
Private Sub SortAll()
Range(Range("TopDescriptio n"), Range("TopDescription").En d(xlDown)) .EntireRow .Sort Key1:=Range("TopCostcode") , Order1:=xlAscending, Key2:=Range("TopPhase" _
), Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False _
, Orientation:=xlTopToBottom , DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal
End Sub
Private Sub SortAll()
Range(Range("TopDescriptio
), Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False _
, Orientation:=xlTopToBottom
xlSortNormal
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Please post your whole code to know the range, anyway try below:
Sub SortData()
Dim Ws As Worksheet
Dim LR As Long
Application.ScreenUpdating = False
Set Ws = ActiveSheet
LR = Ws.Range("A" & Rows.Count).End(xlUp).Row
Ws.Sort.SortFields.Clear
Ws.Sort.SortFields.Add Key:=Range("J1:J" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With Ws.Sort
.SetRange Range("A1:J" & LR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
End Sub
ASKER
OK Thanks!
ASKER
Range(Range("a1"), Range("a" & Rows.Count).End(xlUp)).Ent