ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting macro (https://www.excelbanter.com/excel-programming/401204-sorting-macro.html)

Phrank

Sorting macro
 
I have the following sort macro:

Cells.Select
Selection.Sort Key1:=Range("L2"), Order1:=xlAscending,
Header:=xlYes
Range("A1").Select

This works just fine, but I may have occasion to add , remove, or move
a column. Is there a way to have it sort on a named range? This
would allow for the columns to change but still sort on the given
column without having to go back into the macro and change the Range.
I tried naming a column and having it sort that way, but I was given a
debug error (as below). Thanks for any help.

Cells.Select
Selection.Sort Key1:=Range(Name), Order1:=xlAscending,
Header:=xlYes
Range("A1").Select

Jim May

Sorting macro
 
You'll likley need to put quotes (" ' s) around the Range Name

Selection.Sort Key1:=Range("Name"), Order1:=xlAscending,

"Phrank" wrote:

I have the following sort macro:

Cells.Select
Selection.Sort Key1:=Range("L2"), Order1:=xlAscending,
Header:=xlYes
Range("A1").Select

This works just fine, but I may have occasion to add , remove, or move
a column. Is there a way to have it sort on a named range? This
would allow for the columns to change but still sort on the given
column without having to go back into the macro and change the Range.
I tried naming a column and having it sort that way, but I was given a
debug error (as below). Thanks for any help.

Cells.Select
Selection.Sort Key1:=Range(Name), Order1:=xlAscending,
Header:=xlYes
Range("A1").Select


Phrank

Sorting macro
 
That worked! Thanks Jim.

On Thu, 15 Nov 2007 19:57:00 -0800, Jim May
wrote:

You'll likley need to put quotes (" ' s) around the Range Name

Selection.Sort Key1:=Range("Name"), Order1:=xlAscending,

"Phrank" wrote:

I have the following sort macro:

Cells.Select
Selection.Sort Key1:=Range("L2"), Order1:=xlAscending,
Header:=xlYes
Range("A1").Select

This works just fine, but I may have occasion to add , remove, or move
a column. Is there a way to have it sort on a named range? This
would allow for the columns to change but still sort on the given
column without having to go back into the macro and change the Range.
I tried naming a column and having it sort that way, but I was given a
debug error (as below). Thanks for any help.

Cells.Select
Selection.Sort Key1:=Range(Name), Order1:=xlAscending,
Header:=xlYes
Range("A1").Select



All times are GMT +1. The time now is 05:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com