Sort in Office 2007

  • Thread starter Thread starter XP
  • Start date Start date
X

XP

Using Office 2007 and Win XP;

I recorded a macro to sort a range and I got some gobblety-gook that doesn't
run when I replay the macro.

In my code, I first select a range (e.g. A2:E137) then I want to sort on
column "A".

Can someone please post a generic code example that would do this (Office
2007)?

Thanks much in advance.
 
With ActiveSheet.Range("A2:E137")
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, Header:=xlNo, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

Check if the header argument is correct.
 
Is there any way this code could be written where the range is selected
BEFORE the macro is run? I want to be able to select the range to sort
first, then run the macro.

XP mentioned something about a variable but I'm not sure how to write one
and if it applies to what I want to accomplish.

The code works great but I want to eliminate the range selection in the macro.

Thanks in advance.
Frank
 
This line:
With ActiveSheet.Range("A2:E137")
would become
with Selection



Is there any way this code could be written where the range is selected
BEFORE the macro is run? I want to be able to select the range to sort
first, then run the macro.

XP mentioned something about a variable but I'm not sure how to write one
and if it applies to what I want to accomplish.

The code works great but I want to eliminate the range selection in the macro.

Thanks in advance.
Frank
 
Thank you a million times! It took me over a month of searching, testing,
etc...

It works exactly the way I want it to.
Thanks again.
 
Back
Top