PDA

View Full Version : Clean up Sort



preseb
04-13-2011, 06:34 AM
When I recorded the sort function, it provided me with the exact range that I am using.
I would like to clean it up so it does not matter how many rows my table is.

ActiveWorkbook.Worksheets("Master File").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Master File").Sort.SortFields.Add Key:=Range( _
"C2:C2339"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Master File").Sort.SortFields.Add Key:=Range( _
"B2:B2339"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Master File").Sort
.SetRange Range("A1:O2339")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

BrianMH
04-13-2011, 12:05 PM
change to C:C and B:B and A:O

see if that works.

preseb
04-13-2011, 12:09 PM
I can't believe it was that simple.

Thanks

mdmackillop
04-13-2011, 12:34 PM
Hi Preseb,
Please use the green VBA button to format posted code as shown.