Mel Smith
Well-known Member
- Joined
- Dec 13, 2005
- Messages
- 1,041
- Office Version
- 365
- Platform
- Windows
I am using the following code, which works well, but now I find that I need to add a criteria to the sort. The code sorts column AJ smallest to largest but now I would like to perform the same sort but cells in the range that are zero need to be placed last, rather than after being sorted ending up at the top of the list.
My code is:
My code is:
VBA Code:
lr = Cells(Rows.Count, "AJ").End(xlUp).Row - 8
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add2 Key:= _
Range("AJ4:AJ" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("AE3:AQ" & lr)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Many thanks.
Mel