Thread: sorting range
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default sorting range

Your sorting by column C of the activesheet--not the 3rd column of the first
area.

Maybe...

With myRng
.Sort key1:=.Columns(3), order1:=xlAscending, _
key2:=,Columns(2), order2:=xlAscending, _
key3:=.Columns(6), order3:=xlAscending, _
header:=xlNo, MatchCase:=False, Orientation:=xlTopToBottom
End With

You may want to check to see if that Area has at least 6 columns, too:

if myrng.columns.count < 6 then
'error message or resize or ????



peyman wrote:

hi,
I'm using the following code to sort a selected range based on the columns,
C,B and F.I don't know why the range is sorted only based on Column C?
Sub Rectangle1954_Click()
Dim myRng As Range
Set myRng = Selection.Areas(1)
With myRng
.Sort key1:=Columns("C"), order1:=xlAscending, header:=xlNo,
MatchCase:=False, Orientation:=xlTopToBottom, key2:=Columns("B"),
order1:=xlAscending, header:=xlNo, MatchCase:=False,
Orientation:=xlTopToBottom, key3:=Columns("F"), order1:=xlAscending,
header:=xlNo, MatchCase:=False, Orientation:=xlTopToBottom
End With
End Sub

any help?
thanx


--

Dave Peterson