Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Selection.sort Run-time error '1004'

Hello,

I've got a problem when trying to sort a selection (Range of a
worksheet). Here is the code snipped (similar to the one recorded with
record a macro):

With QACPackageWS
Set rng = .Range(.Cells(1, 1), .Cells(row, col))
rng.Select
Selection.Sort Key1:=Range("E2"), Order1:=xlDescending,
Key2:=Range("G2") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
End With

Excel/VBA stops program execution with a Run-time error '1004'.
Anyone a clue what i did wrong? Thanks for Support!

BR/
tilmp

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Selection.sort Run-time error '1004'

You must activate the sheet before using select could be the problem.
Better though to skip the select altogether. Also, are the E2 and G2
cells on the same sheet, in which case you need .Range("E2") and
..Range("G2")

With QACPackageWS
Set rng = .Range(.Cells(1, 1), .Cells(row, col))
rng.Sort Key1:=Range("E2"), Order1:=xlDescending,
Key2:=Range("G2") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
End With

I assume you have used the line wrapping characters (space followed by
underscore) that lets you break code lines?

regards
Paul

wrote:
Hello,

I've got a problem when trying to sort a selection (Range of a
worksheet). Here is the code snipped (similar to the one recorded with
record a macro):

With QACPackageWS
Set rng = .Range(.Cells(1, 1), .Cells(row, col))
rng.Select
Selection.Sort Key1:=Range("E2"), Order1:=xlDescending,
Key2:=Range("G2") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
End With

Excel/VBA stops program execution with a Run-time error '1004'.
Anyone a clue what i did wrong? Thanks for Support!

BR/
tilmp


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Selection.sort Run-time error '1004'

Are you by chance trying to use this in XL2000 (although originally recorded
in a later version). If so the arguments DataOption1 & DataOption2 are n/a.

Otherwise verify the sort keys are within the range.

Regards,
Peter T

wrote in message
ups.com...
Hello,

I've got a problem when trying to sort a selection (Range of a
worksheet). Here is the code snipped (similar to the one recorded with
record a macro):

With QACPackageWS
Set rng = .Range(.Cells(1, 1), .Cells(row, col))
rng.Select
Selection.Sort Key1:=Range("E2"), Order1:=xlDescending,
Key2:=Range("G2") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
End With

Excel/VBA stops program execution with a Run-time error '1004'.
Anyone a clue what i did wrong? Thanks for Support!

BR/
tilmp



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
Run Time Error 1004: Application or Object Defined Error BEEJAY Excel Programming 4 October 18th 06 04:19 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
Run-time error 1004 with sort Linking to specific cells in pivot table Excel Programming 5 August 30th 05 12:45 AM
Run-time error 1004 with sort Jim Thomlinson[_4_] Excel Programming 0 August 29th 05 09:48 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


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