Sort Macro Compatibility

D

Dan

Can someone help me understand why this macro works in Excel 2007 but not on
Excel 2003?

Sub Sort_Donors()
'
' Sort_Donors Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Application.Goto Reference:="NameList"
ActiveWorkbook.Worksheets("Donor List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Donor List").Sort.SortFields.Add
Key:=ActiveCell. _
Range("A1:A100"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Donor List").Sort
.SetRange ActiveCell.Offset(-1, 0).Range("A1:A101")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
 
D

Dave Peterson

The syntax for sorting has changed from xl2003 to xl2007 (when you recorded your
macro).

But the good thing is that both versions still will work with the old syntax.

With worksheets("Donor List")
with .range("NameList")
.cells.sort key1:=.columns(1), order1:=xlAscending, header:=xlNo
end with
end with

It looks like you're including the header and then resizing the range (including
that header). The code I suggested just ignores that header row and says that
the range doesn't haven't headers.
 
D

Dan

Thank you Dave. I thought it might be something simple like that. Thanks so
much for the quick reply.
 

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

Similar Threads

Modify Sort Routine to inlcude All Data 2
Undo Macro Action 3
Sorting Question 5
VBA 2 Codes 2
Clear Check Box 2
Pictures not being sorted in VBA 2
vba dynamic 1
Stay on Active Sheet 2

Top