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

I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.

Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal

How can I make "B2" a variable so that the sort can work it's way down
the sheet?

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

watch for wordwrap:

Sub test()
Dim lastrow As Long
Dim i As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lastrow
With Range("B" & i, Range("B" & i).End(xlToRight))
.Sort Key1:=Range("B" & i), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Next
End Sub

--


Gary


"LongBeachGuy" wrote in message
ps.com...
I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.

Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal

How can I make "B2" a variable so that the sort can work it's way down
the sheet?



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

For future reference, it is considered bad coding practice to make
selects unles absolutely necessary.
As long as you are certain that you want have any blank cells in your
row, then the xlToRight will work. If you think you may have blank
cells, you can fund the last used column in the row by using
cells(i,"IV").End(xlToLeft) where i is the variable storing the row.
Sub LtoRsort()
Dim i As Long
Dim startCol As Integer
startCol = 2
For i = 2 To Cells(Rows.Count, startCol).End(xlUp).Row
With Range(Cells(i, startCol), _
Cells(i, startCol).End(xlToRight))
.Sort Key1:=Cells(i, startCol), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Next i
End Sub

LongBeachGuy wrote:
I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.

Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal

How can I make "B2" a variable so that the sort can work it's way down
the sheet?


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

I'm using excel 2000. This code fails at DataOption1--"variable not
defined"

Dan

On Oct 9, 11:07 am, "Gary Keramidas" <GKeramidasATmsn.com wrote:
watch for wordwrap:

Sub test()
Dim lastrow As Long
Dim i As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lastrow
With Range("B" & i, Range("B" & i).End(xlToRight))
.Sort Key1:=Range("B" & i), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Next
End Sub

--

Gary

"LongBeachGuy" wrote in message

ps.com...

I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal


How can I make "B2" a variable so that the sort can work it's way down
the sheet?



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

Sub LtoRsort()
Dim i As Long
Dim startCol As Integer
startCol = 2
For i = 2 To Cells(Rows.Count, startCol).End(xlUp).Row
With Range(Cells(i, startCol), _
Cells(i, startCol).End(xlToRight))
.Sort Key1:=Cells(i, startCol), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlLeftToRight
End With
Next i
End Sub
dan dungan wrote:
I'm using excel 2000. This code fails at DataOption1--"variable not
defined"

Dan

On Oct 9, 11:07 am, "Gary Keramidas" <GKeramidasATmsn.com wrote:
watch for wordwrap:

Sub test()
Dim lastrow As Long
Dim i As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lastrow
With Range("B" & i, Range("B" & i).End(xlToRight))
.Sort Key1:=Range("B" & i), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Next
End Sub

--

Gary

"LongBeachGuy" wrote in message

ps.com...

I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal


How can I make "B2" a variable so that the sort can work it's way down
the sheet?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sorting left to right

Dataoption# was added in xl2002. Remove it (and the preceding comma) and try it
again.

dan dungan wrote:

I'm using excel 2000. This code fails at DataOption1--"variable not
defined"

Dan

On Oct 9, 11:07 am, "Gary Keramidas" <GKeramidasATmsn.com wrote:
watch for wordwrap:

Sub test()
Dim lastrow As Long
Dim i As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lastrow
With Range("B" & i, Range("B" & i).End(xlToRight))
.Sort Key1:=Range("B" & i), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Next
End Sub

--

Gary

"LongBeachGuy" wrote in message

ps.com...

I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal


How can I make "B2" a variable so that the sort can work it's way down
the sheet?


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Sorting left to right

Ok, Thanks

On Oct 9, 1:56 pm, Dave Peterson wrote:
Dataoption# was added in xl2002. Remove it (and the preceding comma) and try it
again.



dan dungan wrote:

I'm using excel 2000. This code fails at DataOption1--"variable not
defined"


Dan


On Oct 9, 11:07 am, "Gary Keramidas" <GKeramidasATmsn.com wrote:
watch for wordwrap:


Sub test()
Dim lastrow As Long
Dim i As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row


For i = 2 To lastrow
With Range("B" & i, Range("B" & i).End(xlToRight))
.Sort Key1:=Range("B" & i), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End With
Next
End Sub


--


Gary


"LongBeachGuy" wrote in message


ups.com...


I am trying to make the following codes work for multiple rows. So far
I can only do one row at a time. Please help.


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal


How can I make "B2" a variable so that the sort can work it's way down
the sheet?


--

Dave Peterson



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 rows left to right numerically Carlton A. Barlow Excel Worksheet Functions 1 December 2nd 07 12:40 AM
sorting contents from right to left Kim Excel Worksheet Functions 1 June 7th 07 01:51 PM
Sorting rows (left to right) programmatically Mike[_111_] Excel Programming 0 October 21st 06 09:39 PM
Sorting rows (left to right) programmatically Mike[_111_] Excel Programming 0 October 20th 06 09:05 AM
Sorting Right to Left Kaiser Excel Worksheet Functions 1 October 18th 06 02:30 AM


All times are GMT +1. The time now is 03:13 PM.

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

About Us

"It's about Microsoft Excel"