View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Column Sorting

Ouch. That one hurt!

Tom Ogilvy wrote:

Option Explicit
Sub testme01()
Dim myRng As Range

Set myRng = Worksheets("sheet1").Range("c4:AN4").CurrentRegion

if myrng.row < 4 then _
set myrng = myrng.offset(4-myrng.row)
set myrng = myrng.resize(,38)
With myRng
.Sort Key1:=.Cells(1), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlLeftToRight
End With

End Sub

Assumes you don't have data below your last row that you don't want sorted
and there are no completely blank rows below row 4 until the end of the
data.

--
Regards,
Tom Ogilvy

Todd Huttenstine wrote in message
...
This almost worked, It sorted the columns but did not move
the data under the columns with the columns when it sorted
the alphabetical. How do you fix this?
-----Original Message-----
Try recording a macro when you sort your range.

There's an option button on the sort dialog that allows

you to specify right to
left.

I got this (in xl2002):

Range("C4:AN4").Select
Selection.Sort Key1:=Range("C4"),

Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,

Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal

I'd modify it to something like:

Option Explicit
Sub testme01()
Dim myRng As Range

Set myRng = Worksheets("sheet1").Range("c4:AN4")

With myRng
.Sort Key1:=.Cells(1), Order1:=xlAscending,

Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,

Orientation:=xlLeftToRight
End With

End Sub

(you really meant sort by column???)



Todd Huttenstine wrote:

Ive got a worksheet with a table. On row 4 I have
different categorys. What is the code I would use for

it
to look in Row 4 starting with column C and sort
alphabetical? My data goes from column C to Column AN

in
row 4. I would like to have the code inserted into a
button so I can just click and it sort.

Thank you

Todd Huttenstine

--

Dave Peterson

.


--

Dave Peterson