Results 1 to 8 of 8

Using Sort function in macro crashes

Threaded View

  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    DFW
    MS-Off Ver
    Excel 2003
    Posts
    4

    Using Sort function in macro crashes

    I have a report I produce where I take an XML file, sort it and run some simple formulas then sort another way and run a few more formulas then update a pivot table. The XML files I'm using have the same headers but vary in length. When I set the macro up for a particular XML file everything works fine. When I import another one (different size) I get the error message:

    Run-time error ‘1004’:
    Sort method of Range class failed

    When I look at the code I see that the range is fixed to the XML file I used when setting the macro up. Is there a way to auto-select the table in the macro so I can run the same macro on any size XML?

    The code for the first sort looks like this:
    Sub DSort1()
    '
    ' DSort1 Macro
    ' Macro recorded 6/3/2009 by CCE User
    '
    
    '
        Range("A1:AI76").Sort Key1:=Range("M2"), Order1:=xlAscending, Key2:=Range _
            ("K2"), Order2:=xlAscending, Key3:=Range("N2"), Order3:=xlAscending, _
            Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
            xlTopToBottom, DataOption1:=xlSortTextAsNumbers, DataOption2:= _
            xlSortTextAsNumbers, DataOption3:=xlSortNormal
    End Sub
    Any help here would be greatly appreciated.
    Last edited by sfax39; 06-04-2009 at 03:49 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1