Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Sort code fails

Can anyone tell me why this code fails in Excel 2003 (works fine in Excel 2007)

I get the following error:

object doesn't support this property or method

and the line ActiveSheet.Sort.SortFields.Clear is highlighted


Sub Sort_NoneReturned()
'
'

'
Application.EnableEvents = False
Application.ScreenUpdating = False

ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range( _
"O3:O5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A2:O5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Range("B2").Select

Application.EnableEvents = False
Application.ScreenUpdating = True

End Sub

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

xl2007 has lots more features that xl2003 lacks:

With ActiveSheet.Range("A2:o5000")
.Cells.Sort key1:=.Columns(15), order1:=xlAscending, Header:=xlYes, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

You could add
dataoption1:=xlSortNormal
But that was added in xl2002 (IIRC). Don't include it if you have to support
xl2k, too.

ordnance1 wrote:

Can anyone tell me why this code fails in Excel 2003 (works fine in Excel 2007)

I get the following error:

object doesn't support this property or method

and the line ActiveSheet.Sort.SortFields.Clear is highlighted

Sub Sort_NoneReturned()
'
'

'
Application.EnableEvents = False
Application.ScreenUpdating = False

ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range( _
"O3:O5000"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A2:O5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Range("B2").Select

Application.EnableEvents = False
Application.ScreenUpdating = True

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
Macro to sort variable data range fails Kiwipingu Excel Discussion (Misc queries) 1 June 3rd 10 10:16 PM
Sort fails on one column christophercbrewster via OfficeKB.com Excel Discussion (Misc queries) 2 May 24th 10 06:03 PM
My code fails kirkm[_6_] Excel Programming 3 February 22nd 07 08:44 AM
Code fails if ran more than once Christy Excel Programming 11 August 31st 05 06:57 PM
In Excel, why sort function fails when applied to a list of date? Excel heavy user Excel Discussion (Misc queries) 1 January 18th 05 06:37 PM


All times are GMT +1. The time now is 03:03 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"