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.
Bookmarks