Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Having trouble getting sort to work in a macro

I'm trying to get a sort statement to work within a macro and having very
little success.

here'a a code snippet:

Worksheets("TempLstData").Select

Range("A1:AX256").Sort Key1:=Range("p2"), Order1:=x1Ascending,
Key2:=Range("al2") _
, Order2:=x1Descending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=True _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal


I got this code from funning the macro recorder... I have a small test
worksheet on which this bit of code seems to work, but when I try to run it
within the actual workbook I get the following (very helpful?) error message:

Run-time error '1004'
Sort method of Range class failed.

When I click on the debug link I see the entire sort statement highlited.
The help link takes me to a very non-specific error message about a Macro
error.

ANy help or insights will be greatly appreciated. I'm trying to get this
sort capability added to a worksheet that is due in the morning.

Mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Having trouble getting sort to work in a macro

Perhaps you want to change x1Ascending and x1Descending to xlAscending and
xlDescending. (the letter "l"; not the number "1").

Using Option Explicit would help to avoid these problems in the first place!
:-)

--

Vasant


"Mark" wrote in message
...
I'm trying to get a sort statement to work within a macro and having very
little success.

here'a a code snippet:

Worksheets("TempLstData").Select

Range("A1:AX256").Sort Key1:=Range("p2"), Order1:=x1Ascending,
Key2:=Range("al2") _
, Order2:=x1Descending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=True _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal


I got this code from funning the macro recorder... I have a small test
worksheet on which this bit of code seems to work, but when I try to run

it
within the actual workbook I get the following (very helpful?) error

message:

Run-time error '1004'
Sort method of Range class failed.

When I click on the debug link I see the entire sort statement highlited.
The help link takes me to a very non-specific error message about a Macro
error.

ANy help or insights will be greatly appreciated. I'm trying to get this
sort capability added to a worksheet that is due in the morning.

Mark



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Having trouble getting sort to work in a macro

You have misspelled the constants xlascending and xldescending by replacing
the "L" with the numeral 1. That can cause such an error.

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
I'm trying to get a sort statement to work within a macro and having very
little success.

here'a a code snippet:

Worksheets("TempLstData").Select

Range("A1:AX256").Sort Key1:=Range("p2"), Order1:=x1Ascending,
Key2:=Range("al2") _
, Order2:=x1Descending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=True _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal


I got this code from funning the macro recorder... I have a small test
worksheet on which this bit of code seems to work, but when I try to run

it
within the actual workbook I get the following (very helpful?) error

message:

Run-time error '1004'
Sort method of Range class failed.

When I click on the debug link I see the entire sort statement highlited.
The help link takes me to a very non-specific error message about a Macro
error.

ANy help or insights will be greatly appreciated. I'm trying to get this
sort capability added to a worksheet that is due in the morning.

Mark



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Having trouble getting sort to work in a macro

Thank you.

I would literally never have figured out the the character in question was a
lowercase "L", not a 1. It makes sense, now ('excel',duh) but, as a complete
newbie to VB, I assumed that "x1" was a data type precursor to let the
compiler know that what was coming needed to be converted (similarly to how
hex constants are entered into code in other languages).

Arg.

You are my new hero :-)

"Vasant Nanavati" wrote:

Perhaps you want to change x1Ascending and x1Descending to xlAscending and
xlDescending. (the letter "l"; not the number "1").

Using Option Explicit would help to avoid these problems in the first place!
:-)

--

Vasant


"Mark" wrote in message
...
I'm trying to get a sort statement to work within a macro and having very
little success.

here'a a code snippet:

Worksheets("TempLstData").Select

Range("A1:AX256").Sort Key1:=Range("p2"), Order1:=x1Ascending,
Key2:=Range("al2") _
, Order2:=x1Descending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=True _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal


I got this code from funning the macro recorder... I have a small test
worksheet on which this bit of code seems to work, but when I try to run

it
within the actual workbook I get the following (very helpful?) error

message:

Run-time error '1004'
Sort method of Range class failed.

When I click on the debug link I see the entire sort statement highlited.
The help link takes me to a very non-specific error message about a Macro
error.

ANy help or insights will be greatly appreciated. I'm trying to get this
sort capability added to a worksheet that is due in the morning.

Mark




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 Trouble Doug Mc New Users to Excel 5 December 16th 09 05:21 PM
Sort, Copy, and Paste macro, must execute twice to work B. CLAY Excel Discussion (Misc queries) 2 May 26th 09 10:07 PM
sort & expand trouble flo Excel Discussion (Misc queries) 0 February 13th 07 05:21 PM
Trouble getting the OFFSET fo work JimP Excel Programming 7 July 29th 04 01:49 PM
Trouble to sort an array in Excel using VBA choco140 Excel Programming 1 August 15th 03 07:24 AM


All times are GMT +1. The time now is 04:25 AM.

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"