#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 46
Default Automatic sort macro

Hi all
E3:F8 represent the results of soccer matches. G3:O6 are the resulting
league positions of the 4 teams in the league. I want the league positions to
be updated automatically as the results are entered. Therefore the sort
should be on column N firstly (points scored) then column O which is the goal
difference then on column L which is goals scored. I recorded a macro which
did this and then copied & pasted the code into a Calculate event macro. The
recorded macro version works fine but the Calculate event produces a runtime
error and reports €œMethod €˜Apply of object €˜Sort failed. Can you tell me
what I need to amend in order to get this to work correctly. My code is as
below and I would like to thank you for any help you can give.

Private Sub Worksheet_Calculate()

Range("G3:O6").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("N3:N6"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("O3:O6"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("L3:L6"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("G3:O6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Al

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,522
Default Automatic sort macro

I'm not terribly familiar with 2007 sorting macros but
Try in a worksheet_change event that restricts to the last column where you
enter the data before the sort.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"gramps" wrote in message
...
Hi all
E3:F8 represent the results of soccer matches. G3:O6 are the resulting
league positions of the 4 teams in the league. I want the league positions
to
be updated automatically as the results are entered. Therefore the sort
should be on column N firstly (points scored) then column O which is the
goal
difference then on column L which is goals scored. I recorded a macro
which
did this and then copied & pasted the code into a Calculate event macro.
The
recorded macro version works fine but the Calculate event produces a
runtime
error and reports €œMethod €˜Apply of object €˜Sort failed. Can you tell
me
what I need to amend in order to get this to work correctly. My code is as
below and I would like to thank you for any help you can give.

Private Sub Worksheet_Calculate()

Range("G3:O6").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("N3:N6"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("O3:O6"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("L3:L6"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("G3:O6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Al


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 46
Default Automatic sort macro

Sorry for delay replying. you puy me on the right lines and now up & running.
Thanks for your help
Al

"Don Guillett" wrote:

I'm not terribly familiar with 2007 sorting macros but
Try in a worksheet_change event that restricts to the last column where you
enter the data before the sort.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"gramps" wrote in message
...
Hi all
E3:F8 represent the results of soccer matches. G3:O6 are the resulting
league positions of the 4 teams in the league. I want the league positions
to
be updated automatically as the results are entered. Therefore the sort
should be on column N firstly (points scored) then column O which is the
goal
difference then on column L which is goals scored. I recorded a macro
which
did this and then copied & pasted the code into a Calculate event macro.
The
recorded macro version works fine but the Calculate event produces a
runtime
error and reports €œMethod €˜Apply of object €˜Sort failed. Can you tell
me
what I need to amend in order to get this to work correctly. My code is as
below and I would like to thank you for any help you can give.

Private Sub Worksheet_Calculate()

Range("G3:O6").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("N3:N6"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("O3:O6"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("L3:L6"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("G3:O6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Al


.

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
Automatic sort ALEX Excel Discussion (Misc queries) 0 July 27th 06 07:55 PM
Automatic Sort ferg Excel Discussion (Misc queries) 2 July 20th 06 01:33 PM
Automatic League Sort Blade2304 Excel Worksheet Functions 4 May 18th 06 02:37 PM
Automatic Sort Blade2304 Excel Discussion (Misc queries) 1 May 18th 06 10:15 AM
automatic sort Robert Excel Worksheet Functions 6 June 28th 05 02:28 PM


All times are GMT +1. The time now is 12:51 PM.

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"