Dear all,
In the file attached, is a sheet showing an excerpt of football league. Could you guys help in showing how I can fill out columns G, H, I, J? Remember, at one point a team is a home and another point the team is away.
your kind help will be highly appreciated
Bulls
Welcome to the forum, embwabili.
Both this and your other post look a lot like homework problems. We don't do those, but will help if you have a specific question other than, "How do I do this?"
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Hi, shg, sharp eye, connecting the 2 posts :-)
But actually they are not homework problems, am simply trying to develop my own custom system to beat the bookies. Want to make more informed decisions before I place my next bet. Can you now help?
Hello embwabili,
Welcome to the Forum!
The attached workbook has a button to run the macro. When the macro runs it will fill in the worksheet columns "G:J" with the scores of the 6 most recent games. All the data is first sorted by date in descending order and then alphabetically by team. Here is the macro that has been added...
'Written: March 15, 2010 'Author: Leith Ross Sub LoadTeamScores() Dim Cell As Range Dim Cnt As Integer Dim DataRng As Range Dim DataRow1 As String Dim Goals As Variant Dim Item As Variant Dim Key As String Dim RngEnd As Range Dim Teams As Object Dim Wks As Worksheet Set Wks = Worksheets("Sheet1") DataRow1 = "A2:F2" Set DataRng = Wks.Range(DataRow1) Set RngEnd = Wks.Cells(Rows.Count, DataRng.Column).End(xlUp) If RngEnd.Row < DataRng.Row Then Exit Sub Set DataRng = Wks.Range(DataRng, RngEnd) Set Teams = CreateObject("Scripting.Dictionary") Teams.CompareMode = vbTextCompare DataRng.Offset(-1, 0).Sort _ Key1:=DataRng.Cells(1, 1), Order1:=xlDescending, _ Key2:=DataRng.Cells(1, 2), Order2:=xlAscending, Header:=xlYes, _ MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal For Each Cell In DataRng.Columns(2).Cells Key = Trim(Cell) Set Item = Cell.Offset(0, 2).Resize(1, 2) If Key <> "" Then If Not Teams.Exists(Key) Then Teams.Add Key, "1," & Item(1).Text & "," & Item(2).Text Else X = Cell.Address Goals = Split(Teams(Key), ",") Cnt = Goals(0) If Cnt < 6 Then Goals(0) = Cnt + 1 Goals(1) = Goals(1) + Item(1) Goals(2) = Goals(2) + Item(2) Teams(Key) = Join(Goals, ",") End If End If End If Next Cell For R = 1 To DataRng.Rows.Count With DataRng Goals = Split(Teams(.Item(R, 2).Text), ",") .Item(R, 7).Value = Goals(1) .Item(R, 8).Value = Goals(2) Goals = Split(Teams(.Item(R, 3).Text), ",") .Item(R, 9).Value = Goals(1) .Item(R, 10).Value = Goals(2) End With Next R End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Dear Leith,
Thanks so very much for the help. Unfortunately, when I run the macro and manually crosscheck the values/results, I see that it is not returning correct values. I have tried to see if there is an offset or particular trend in the inconsistency but there seems to be no correlation.
Kindly re-crosscheck.
Thanks once again
Regards
Bulls
Needless to say it generally helps if you provide expected results - this way everyone can validate their logic (eg "current" game included in the last n results ?)
I appreciate you have (seemingly) requested code based solution given Forum in which this is located but just to illustrate that you can (if so desired) resolve with formulae see attached.
On very large data sets it would make sense to use more helpers to negate need for Arrays / SUMPRODUCT etc... a UDF / Sub Routine is not a bad idea
To reiterate - I'm not advocating this above and beyond a VBA based solution - merely an alternative.
EDIT: upload removed and replaced by version in latter post (#10)
Last edited by DonkeyOte; 03-16-2010 at 07:58 AM.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Dear DonkeyOte,
Having posted to this forum was in belief that I would get help here better than in any other place, not because I preferred a particular method of solution over any other. What works first is what I go with and later I can consider what works elegantly. Feel free to suggest what works.
How to verify logic?
col G is filled by summing all the goals scored by a home team(col b) in last six previous appearances before the current fixture. The six appearances are counted regardless of whether that team featured at home or away. What matters are 6 appearances before the row in question. So the summation has to pick value from either col D or E for those 6 appearances depending on whether the team was away or at home.
col H is filled by summing all the goals that the home team conceded in fixtures considered above.
col I is filled by using the same logic like for G but this time considering the away team(col C).
col J is filled by using the same logic like for H but this time considering the away team(col C).
The current fixture is not counted among the 6, only the previous ones.
I hope it is more clear now.
DonkeyOte, are the formulae you put in the sheet examples or they are the ones I should use in verification?
Thanks alot once again
Regards
Bulls
embwabili, I think you misunderstood my point... you should provide expected results in your sample file at least for a few cells.
Not doing so means people are guessing based on interpretation - they having nothing empirical against which to measure their own results.
The prior attachment was pretty self explanatory I think, however, given the below:Originally Posted by embwabili
they will need to be "tweaked" given I had incorrectly presumed "current" result to be inclusive as opposed to exclusive (hence earlier point regards providing expected results).Originally Posted by embwabili
To tweak you must change the 5 to a 6 in the SMALL arrays in L2 & M2 - remembering to reset the Array (CTRL + SHIFT + ENTER) - then copy down over remaining rows.
Adjust G:J by removing reference to current score if not to be included (ie remove $D2+ etc...)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Dear DonkeyOte,
You brought a smile to my face. The formulas are working OK with the current match included, thanks. Following your instructions, I'll do the tweaking to remove the current match.
There's one issue though, the calculations are coming bottom up i.e starting with the newer matches instead of the older ones. Could you help change them to start from the top going downwards i.e start with the older matches and calculations going on downwards as the league progresses?
Thanks alot DonkeyOte
Very warm regards
Bulls
see revision
(earlier version will be removed for space)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
For all purposes and intents, this thread canbe considered solved and closed. Thanks so much DonkeyOte
Last edited by embwabili; 03-16-2010 at 08:39 AM. Reason: I want to put solved to appear in the thread header
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks