Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Macro to sort variable data range fails

Hi,

Can you please help me identify why this macro is failing with the
following error?

Runtime error 1004: Sort method of Range class failed

Row 7 is the header row
Data range has a variable number of rows (so using end(xldown) to
select the range)
Using column BA to select a contiguous range of cells as all cells are
populated in the column
Then using that selection to select entire rows in my list
Sorting as per criteria using row 7 as header row


Rows("7:7").Select
Range("BA7").Activate
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.EntireRow.Select
Selection.Sort Key1:=Range("BE8"), Order1:=xlAscending,
Key2:=Range("BB8" _
), Order2:=xlDescending, Key3:=Range("BM8"),
Order3:=xlDescending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=
_
xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Range("BN8:BN9").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("BN9").Select

Thanks,
AS
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default Macro to sort variable data range fails


It worked for me in Xl 2003. I made sure there was data in all three of the columns.
I also reformatted the code, as your post omitted some line continuation characters "_".
'---
Rows("7:7").Select
Range("BA7").Activate
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.EntireRow.Select
Selection.Sort Key1:=Range("BE8"), Order1:=xlAscending, _
Key2:=Range("BB8"), Order2:=xlDescending, _
Key3:=Range("BM8"), Order3:=xlDescending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
Range("BN8:BN9").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("BN9").Select
'---
Jim Cone
Portland, Oregon USA
http://www.contextures.com/excel-sort-addin.html




"Kiwipingu"
wrote in message
Hi,
Can you please help me identify why this macro is failing with the
following error?
Runtime error 1004: Sort method of Range class failed
Row 7 is the header row
Data range has a variable number of rows (so using end(xldown) to
select the range)
Using column BA to select a contiguous range of cells as all cells are
populated in the column
Then using that selection to select entire rows in my list
Sorting as per criteria using row 7 as header row

Rows("7:7").Select
Range("BA7").Activate
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.EntireRow.Select
Selection.Sort Key1:=Range("BE8"), Order1:=xlAscending,
Key2:=Range("BB8" _
), Order2:=xlDescending, Key3:=Range("BM8"),
Order3:=xlDescending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=
_
xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Range("BN8:BN9").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("BN9").Select

Thanks,
AS
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
Macro to Sort A-Z a variable range of cells Keith B Excel Discussion (Misc queries) 1 September 9th 09 03:31 AM
VBA Variable Range Sort Tony Excel Discussion (Misc queries) 4 April 9th 09 08:21 PM
How do I use a variable in a sort macro APealin Excel Worksheet Functions 0 October 12th 06 03:40 PM
Macro - Data Sort -Variable Selection Frantic Excel-er Excel Discussion (Misc queries) 3 June 6th 05 10:33 PM
1-variable Data Table dependent on MS Query fails to update correctly [email protected] Excel Discussion (Misc queries) 0 March 30th 05 07:43 PM


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