Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Sort Macro Compatibility

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sort Macro Compatibility

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.





Dan wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Sort Macro Compatibility

Thank you very much Dave. I thought it might be something as easy as that.

"Dave Peterson" wrote:

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.





Dan wrote:

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


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Sort Macro Compatibility

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

"Dave Peterson" wrote:

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.





Dan wrote:

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


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Testing Reverse Compatibility and Compatibility in General dim Excel Discussion (Misc queries) 4 January 8th 08 01:02 PM
Macro Compatibility ARCUser Excel Programming 0 April 30th 07 09:00 PM
Macro compatibility with Excel 97 Chris L Excel Programming 6 September 26th 06 12:51 AM
Macro compatibility between excel XP and 97 darryl26 Excel Programming 0 July 30th 04 06:55 PM
Macro Compatibility M.Vance Excel Programming 1 August 29th 03 07:14 PM


All times are GMT +1. The time now is 01:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"