# Solved: excel macro-sort



## nueces (Jun 21, 2008)

I have Office 2003 and need the code for a sort macro. I need to sort data in the fields from A3-K64 by data in the K column in descending order. I tried the following code, but it doesn't work:


Range("A3:K64").sortKey1:=Range("K3:K64"),
Order1:=x1Descending,
Header:=x1NoGuess,
OrderCustom:=1,
MatchCase:=False,
Orientation:=x1TopToBottom,
DataOption1:=x1SortNormal

Can you help?


----------



## slurpee55 (Oct 20, 2004)

This seems to work:

Application.CutCopyMode = False
Range("A3:K64").Sort Key1:=Range("K3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


----------



## nueces (Jun 21, 2008)

Fantastic. I took your sort code and added it into the 5 steps I need for a macro to do:

ActiveWorkbook.Save

CutCopyMode = False
Range("A5:K64").Sort Key1:=Range("K5"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

ActiveWorkbook.PrintOut

CutCopyMode = False
Range("A5:K64").Sort Key1:=Range("A5"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'
ActiveWorkbook.Save

End Sub

Not knowing a thing about macros, I have spent a good solid 7 days trying to learn and create the code.

Thanks for your help


----------



## slurpee55 (Oct 20, 2004)

I just noticed that you wanted K sorted in descending order - I did my macro in ascending order, so you may wish to change "Order1:=xlAscending" in the second part of your macro


----------



## nueces (Jun 21, 2008)

Thanks. That is what I did. I really appreciate you providing me the code. The Macro does exactly what I want it to.

Thanks again


----------

