Link to cross-post:
http://chandoo.org/forum/threads/vba...7/#post-203641
https://www.mrexcel.com/forum/excel-...ml#post4814278
I have an Excel spreadsheet that I need to sort 3 columns and varying rows (see below). What I would like is VBA code to sort all columns and rows through item 'P' by Quantity (largest to smallest). Then I need to sort all 3 columns a second time by Sort Order (smallest to largest) neglecting the items with zero quantities. The number of items will always be the same so the first sort range will always be the same.
Here is a link to a spreadsheet similar to the one I will be using: https://app.box.com/s/zxvg9acycxrqv067vfc8kct4rroww6qp
I tried to record a macro for this but it only works for this specific example (Items may not always have quantities and/or the quantities will change value so the second sort range (rows) will change). Here is what the macro recorded:
Sub Sort1()
'
' Sort1 Macro
'
'
Range("A4:C20").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A5:A20") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A4:C20")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A4:C16").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C5:C16") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A4:C16")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Can someone provide help? Thanks!
Bookmarks