#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default sort method

I'm having trouble with the sort method, but no clue as to why. Here is my
code:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1 = Sheets("Sheet1").Range("B1")
End With

I've also tried just Sheets("Sheet1").Range("A1:B23").Sort but I'm
continually getting a Sort Method of Range Class Failed error. I just want
to sort the range I am going to use to populate a listbox. If I select the
range then sort the selection it seems to work, but I didn't think I had to
select a range to be able to use the sort method. Any help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default sort method


Ben,

Excel likes to be told exactly what to do, and the parameter syntax needs to
be precise: you were missing the Order1 parameter, and your need a colon
after the key1, along these lines:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1:=Sheets("Sheet1").Range("B1"), Order1:=xlAscending
End With

HTH,
Bernie
MS Excel MVP


"benb" wrote in message
...
I'm having trouble with the sort method, but no clue as to why. Here is

my
code:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1 = Sheets("Sheet1").Range("B1")
End With

I've also tried just Sheets("Sheet1").Range("A1:B23").Sort but I'm
continually getting a Sort Method of Range Class Failed error. I just

want
to sort the range I am going to use to populate a listbox. If I select

the
range then sort the selection it seems to work, but I didn't think I had

to
select a range to be able to use the sort method. Any help?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sort method

Excel isn't quite that demanding: (from help on Sort)

Order1 Optional XlSortOrder. The sort order for the field or range
specified in Key1.

XlSortOrder can be one of these XlSortOrder constants.
xlDescending. Sorts Key1 in descending order.
xlAscending ***default***. Sorts Key1 in ascending order.

Emphasis (***) added.

--
Regards,
Tom Ogilvy



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...

Ben,

Excel likes to be told exactly what to do, and the parameter syntax needs

to
be precise: you were missing the Order1 parameter, and your need a colon
after the key1, along these lines:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1:=Sheets("Sheet1").Range("B1"), Order1:=xlAscending
End With

HTH,
Bernie
MS Excel MVP


"benb" wrote in message
...
I'm having trouble with the sort method, but no clue as to why. Here is

my
code:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1 = Sheets("Sheet1").Range("B1")
End With

I've also tried just Sheets("Sheet1").Range("A1:B23").Sort but I'm
continually getting a Sort Method of Range Class Failed error. I just

want
to sort the range I am going to use to populate a listbox. If I select

the
range then sort the selection it seems to work, but I didn't think I had

to
select a range to be able to use the sort method. Any help?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sort method

You have a syntax error

With Sheets("Sheet1").Range("A1:B23")
.Sort key1:= Sheets("Sheet1").Range("B1")
End With

--
Regards,
Tom Ogilvy


"benb" wrote in message
...
I'm having trouble with the sort method, but no clue as to why. Here is

my
code:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1 = Sheets("Sheet1").Range("B1")
End With

I've also tried just Sheets("Sheet1").Range("A1:B23").Sort but I'm
continually getting a Sort Method of Range Class Failed error. I just

want
to sort the range I am going to use to populate a listbox. If I select

the
range then sort the selection it seems to work, but I didn't think I had

to
select a range to be able to use the sort method. Any help?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default sort method

Range("A1:B23").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, header:=xlGuess,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal

this has worked for me - however, i wasn't using the 'with'

don't know if this will work for your situation or not

J

"benb" wrote:

I'm having trouble with the sort method, but no clue as to why. Here is my
code:

With Sheets("Sheet1").Range("A1:B23")
.Sort key1 = Sheets("Sheet1").Range("B1")
End With

I've also tried just Sheets("Sheet1").Range("A1:B23").Sort but I'm
continually getting a Sort Method of Range Class Failed error. I just want
to sort the range I am going to use to populate a listbox. If I select the
range then sort the selection it seems to work, but I didn't think I had to
select a range to be able to use the sort method. Any help?



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
Sort Method more than 3 cols Molasses26 Excel Programming 1 March 31st 05 04:13 PM
Using the Sort Method Jill E Excel Programming 2 August 6th 04 01:29 PM
Sort Method question CG Rosén Excel Programming 2 July 1st 04 06:12 PM
Sort Method Squid[_3_] Excel Programming 3 March 2nd 04 02:25 PM
Sort method of range Richard Clarke Excel Programming 7 July 25th 03 04:42 PM


All times are GMT +1. The time now is 01:04 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"