PDA

View Full Version : Solved: Sort will NOT Sort



PAB
03-15-2012, 06:55 AM
Good afternoon,

I have this Macro that will NOT sort for some reason.

Option Explicit
Option Base 1
Sub Sort_Numbers_For_Patent_Systems()
With Application
.ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
End With
With Sheets("Patent Systems")
Range("T14:U20").Select
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("U14:U20") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.Sort
.Orientation = xlTopToBottom
.Apply
End With
Range("R51").Select
With Application
.DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
End With
End Sub
I know it is probably something really simple but I can't seem to get it working.
Thanks in advance.

Regards,
PAB

mancubus
03-15-2012, 08:01 AM
hi.

try


With Sheets("Patent Systems")
.Range("T14:U20").Sort , Key1:=.Range("U14"), Order1:=xlDescending, Header:=xlGuess
End With

mancubus
03-15-2012, 08:08 AM
or with a one-liner


Sheets("Patent Systems").Range("T14:U20").Sort , _
Key1:=Sheets("Patent Systems").Range("U14"), _
Order1:=xlDescending, _
Header:=xlGuess

mancubus
03-15-2012, 08:11 AM
the reason why your procedure does not work is:


With Worksheets("Patent Systems")
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("U14:U20"), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("T14:U20")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With

PAB
03-17-2012, 01:00 PM
Hi mancubus,

Thanks very much, that has sorted it.
Sorry to have not replied before but I have been away for a few days.
Thanks again.

Regards,
PAB

mancubus
03-17-2012, 02:45 PM
you're welcome PAB.