Help with SORT property in xl2007 and xl2007 !!!!!!!!!!!!!!!!!!!!

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

I have this line of code in my macro. Someone with Excel 2003 can go past it.

BOReportWS.Sort.SortFields.Clear

Is there a way to get it to run in xl2003?


'BOReportWS.Sort.SortFields.Add Key:=Range("A3:A" & BO_DownloadWS_lastRow)
 
xl2007 still supports the old syntax. So you could create the macro (record
it???) in xl2003 and it'll work ok.

This may help (or not!):

Dim wks As Worksheet
Dim myRng As Range

Set wks = Worksheets("Sheet9999")

With wks
Set myRng = .Range("A3:x" & BO_DownloadWS_lastRow)
End With

With myRng
.Cells.Sort _
key1:=.Columns(1), order1:=xlAscending, _
key2:=.Columns(3), order1:=xlAscending, _
header:=xlYes
End With

This is sorting A3:X(lastrow) by columns A and C. And the data has header in
the first row.
 
Thanks Dave.
I was thinking of actually using both versions by inserting an:
If Application.Version>12.0 then
Use xl2007 syntax
ElseIf Application.Version<12.0 then
Use xl2003 syntax
End If
 
Unless you're doing something unique to xl2007, I wouldn't bother.
 
xl2007 still supports the old syntax.  So you could create the macro (record
it???) in xl2003 and it'll work ok.

This may help (or not!):

    Dim wks As Worksheet
    Dim myRng As Range

    Set wks = Worksheets("Sheet9999")

    With wks
        Set myRng = .Range("A3:x" & BO_DownloadWS_lastRow)
    End With

    With myRng
        .Cells.Sort _
            key1:=.Columns(1), order1:=xlAscending, _
            key2:=.Columns(3), order1:=xlAscending, _
            header:=xlYes
    End With

This is sorting A3:X(lastrow) by columns A and C.  And the data has header in
the first row.

This line is wrong key2:=.Columns(3), order1:=xlAscending, _
This line is correct key2:=.Columns(3), order2:=xlAscending, _
 
Thanks for the correction.



Javed wrote:
This line is wrong key2:=.Columns(3), order1:=xlAscending, _
This line is correct key2:=.Columns(3), order2:=xlAscending, _
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top