Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Sorting left to right programatically

I can record the following macro...

Columns("AY:BE").Select
Selection.Sort Key1:=Range("AY1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal

but I need the starting and end points of the sort to vary. When I assign
variables to the...

AY = colS
BE = colE
last row = endrow


Range(Cells(1, colS), Cells(colE, EndRow)).Sort
Key1:=Sheets(1).Range(Cells(1, colS)), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


When this runs i get a Run Time Error 1004... so something's not pointing to
the right cell... what am I doing wrong?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Sorting left to right programatically

Range(Cells(1, colS), Cells(colE, EndRow)).Sort _
Key1:=Sheets(1).Cells(1, colS), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlLeftToRight, DataOption1:=xlSortNormal


--
__________________________________
HTH

Bob

"jayklmno" wrote in message
...
I can record the following macro...

Columns("AY:BE").Select
Selection.Sort Key1:=Range("AY1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal

but I need the starting and end points of the sort to vary. When I assign
variables to the...

AY = colS
BE = colE
last row = endrow


Range(Cells(1, colS), Cells(colE, EndRow)).Sort
Key1:=Sheets(1).Range(Cells(1, colS)), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


When this runs i get a Run Time Error 1004... so something's not pointing
to
the right cell... what am I doing wrong?



  #3   Report Post  
Posted to microsoft.public.excel.programming
CFS CFS is offline
external usenet poster
 
Posts: 12
Default Sorting left to right programatically

Try this:

colS = Columns("AY").Column
colE = Columns("BE").Column
EndRow = Range("AY65536").End(xlUp).Row

--
CFS


"jayklmno" wrote:

I can record the following macro...

Columns("AY:BE").Select
Selection.Sort Key1:=Range("AY1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal

but I need the starting and end points of the sort to vary. When I assign
variables to the...

AY = colS
BE = colE
last row = endrow


Range(Cells(1, colS), Cells(colE, EndRow)).Sort
Key1:=Sheets(1).Range(Cells(1, colS)), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


When this runs i get a Run Time Error 1004... so something's not pointing to
the right cell... what am I doing wrong?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Sorting left to right programatically

hi
if everything is properly dim'ed then change this line
Range(Cells(1, colS), Cells(colE, EndRow)).Sort
to
Range(Cells(1, colS), Cells(EndRow, colE)).Sort

should work then

regards
FSt1

"jayklmno" wrote:

I can record the following macro...

Columns("AY:BE").Select
Selection.Sort Key1:=Range("AY1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal

but I need the starting and end points of the sort to vary. When I assign
variables to the...

AY = colS
BE = colE
last row = endrow


Range(Cells(1, colS), Cells(colE, EndRow)).Sort
Key1:=Sheets(1).Range(Cells(1, colS)), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


When this runs i get a Run Time Error 1004... so something's not pointing to
the right cell... what am I doing wrong?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Sorting left to right programatically

That did it... thanks! Note to self... row then column...

"FSt1" wrote:

hi
if everything is properly dim'ed then change this line
Range(Cells(1, colS), Cells(colE, EndRow)).Sort
to
Range(Cells(1, colS), Cells(EndRow, colE)).Sort

should work then

regards
FSt1

"jayklmno" wrote:

I can record the following macro...

Columns("AY:BE").Select
Selection.Sort Key1:=Range("AY1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal

but I need the starting and end points of the sort to vary. When I assign
variables to the...

AY = colS
BE = colE
last row = endrow


Range(Cells(1, colS), Cells(colE, EndRow)).Sort
Key1:=Sheets(1).Range(Cells(1, colS)), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


When this runs i get a Run Time Error 1004... so something's not pointing to
the right cell... what am I doing wrong?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting left to right LongBeachGuy Excel Programming 6 October 10th 07 12:55 AM
sorting contents from right to left Kim Excel Worksheet Functions 1 June 7th 07 01:51 PM
Sorting Right to Left Kaiser Excel Worksheet Functions 1 October 18th 06 02:30 AM
programatically color fonts and auto sorting [email protected] Excel Programming 2 December 26th 05 07:03 AM
Sorting in reverse (from right-to-left and from top-to-bottom) retman Excel Discussion (Misc queries) 6 April 1st 05 09:29 AM


All times are GMT +1. The time now is 06:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"