![]() |
Sort in Office 2007
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. |
Sort in Office 2007
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. XP wrote: 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. -- Dave Peterson |
Sort in Office 2007
Thanks Dave!
I'm presuming I can substitute a variable for the range...? Thanks! "Dave Peterson" wrote: 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. XP wrote: 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. -- Dave Peterson |
Sort in Office 2007
If you do it right <vbg.
XP wrote: Thanks Dave! I'm presuming I can substitute a variable for the range...? Thanks! "Dave Peterson" wrote: 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. XP wrote: 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. -- Dave Peterson -- Dave Peterson |
Sort in Office 2007
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 "Dave Peterson" wrote: If you do it right <vbg. XP wrote: Thanks Dave! I'm presuming I can substitute a variable for the range...? Thanks! "Dave Peterson" wrote: 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. XP wrote: 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. -- Dave Peterson -- Dave Peterson |
Sort in Office 2007
This line:
With ActiveSheet.Range("A2:E137") would become with Selection FrankTimJr wrote: 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 "Dave Peterson" wrote: If you do it right <vbg. XP wrote: Thanks Dave! I'm presuming I can substitute a variable for the range...? Thanks! "Dave Peterson" wrote: 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. XP wrote: 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. -- Dave Peterson -- Dave Peterson -- Dave Peterson |
Sort in Office 2007
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. "Dave Peterson" wrote: This line: With ActiveSheet.Range("A2:E137") would become with Selection FrankTimJr wrote: 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 "Dave Peterson" wrote: If you do it right <vbg. XP wrote: Thanks Dave! I'm presuming I can substitute a variable for the range...? Thanks! "Dave Peterson" wrote: 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. XP wrote: 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. -- Dave Peterson -- Dave Peterson -- Dave Peterson |
All times are GMT +1. The time now is 10:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com