Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to sort XLS data

Status
Not open for further replies.

tekkyun

Technical User
Oct 23, 2003
122
GB
Can anyone help me with a piece of code that I currently get 'application-defined or object-defined error' with?

I am trying to simply sort the data with XL spreadsheet using access sub. The code bombs out at line XLRange.sort.....
I have simply copied and pasted the code from xl macro into access, but I guess the syntax is different somewhere?

Current code is as follows:-
rng = "A:AA"
Set xlRange = xlSht.Range(rng)
xlRange.Sort Key1:=Range("E2"), Order1:=xlAscending, Key2:=Range("H2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortTextAsNumbers
 


Hi,

reference the xl sheet for each range in the expression...
Code:
    rng = "A:AA"
    Set xlRange = xlSht.Range(rng)
    xlRange.Sort _
        Key1:=[b]xlSht.[/b]Range("E2"), Order1:=xlAscending, _
        Key2:=[b]xlSht.[/b]Range("H2"), Order2:=xlAscending, _
        Header:=[b][red]xlGuess[/red][/b], _
        OrderCustom:=1, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, _
        DataOption2:=xlSortTextAsNumbers
also, you ought the tell the sort whether or not you have a header, if you know.

Skip,

[glasses] [red][/red]
[tongue]
 
Thanks Skip, works a treat. I had a feeling it would be simple.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top