PDA

View Full Version : Column Sorting



alliejane
07-15-2007, 03:57 PM
I recorded a macro so that I could hopefully learn how to code it, but I'm having problems.

ActiveCell.Cells.Select
Selection.Sort Key1:=ActiveCell.Offset(0, 2).Range("A2"), Order1:= _
xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers

What am I doing wrong below?

ActiveCell.CurrentRegion.Select
Range("CurrentRegion").Sort Key1:=Range("C1")

Bob Phillips
07-15-2007, 04:05 PM
CurrentRegion is a VBA range, you are trying to use it as an Excel defined name.

Try



ActiveCell.CurrentRegion.Select
Selection.Sort Key1:=Range("C1")


or better still



ActiveCell.CurrentRegion.Sort Key1:=Range("C1")

alliejane
07-15-2007, 04:28 PM
Thank you!