Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2005, 12:33 AM
Authorized User
 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting

Hi,

I recorded the macro to sort some data in Excel and copied the code into my program. But after doing so, the macro won't work. What could be wrong?

Worksheets("Data").Select
Worksheets("Data").Columns("A:L").Select
Worksheets("Data").Range("L1").Select
Selection.Sort Key1:=Range("L1"), Order1:=xlAscending, Key2:=Range("G1") _
            , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False _
            , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
            xlSortNormal

The error message is "Run-time error '1004': Application-defined or object-defined error.

Pls advise.
Thanks in advance.

 
Old September 19th, 2005, 05:03 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The code works fine.

Try to debug your code and find out where the error occurs.
Set break point in the first row.
Run the code.
After stopping to break point press F8 to run code row by row.

-vemaju

ps. you can remove these lines
Worksheets("Data").Columns("A:L").Select
Worksheets("Data").Range("L1").Select



 
Old September 19th, 2005, 09:31 PM
Authorized User
 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The run-time error happens at the following code:

Selection.Sort Key1:=Range("L1"), Order1:=xlAscending, Key2:=Range("G1") _
            , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False _
            , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
            xlSortNormal

What other possible errors could there be?

Please advise. Thanks in advance.

Regards






Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting member XSLT 25 July 13th, 2007 08:44 AM
SORTING pallone XSLT 3 October 29th, 2006 08:45 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Sorting? pbernardo XSLT 2 October 27th, 2003 11:34 AM
Need help Sorting athanatos XSLT 5 August 11th, 2003 07:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.