+ Reply to Thread
Results 1 to 10 of 10

Creating formula which auto looks up specific data & makes calculation based on that data

  1. #1
    Registered User
    Join Date
    11-02-2014
    Location
    London
    MS-Off Ver
    Excel For Mac 2011
    Posts
    10

    Creating formula which auto looks up specific data & makes calculation based on that data

    Okay; I made another thread yesterday which turned out to have a simple answer, but I'm certain this is much more complicated, so thank you so much to anyone who can help with this. It's a toughie I think. I'll explain first what I have in my spreadsheet.

    So my spreadsheet data is UK Soccer results. This data is essentially all of the results from the English Premier League so far. These are listed in my sheet entitled 'E0'. The column headings in this table of results are:

    Date
    Home Team
    Away Team
    Full Time Home Goals
    Full Time Away Goals (this and the above column therefore give the full time score!)
    Full Time Result (This is expressed as either H, D or A. H = Home Win, D = Draw, A = Away Win)

    In a separate sheet, entitled 'Fixtures', I have the next fixtures for the Premier League, listed as two separate columns for the Home Team and Away Team. Next to these fixtures, I have three more columns entitled 'Home Win', 'Draw' and 'Away Win'. What I want to do is use the formula I have created personally to calculate the percentage probability of the result of the next fixture being either a Home Win, Away Win or Draw (so of course, these percentages will be listed in the three columns next to the fixtures and will add up to 100%).

    ------------------------------------
    ------------------------------------

    To give you an idea of what I want to automate, my 'formula' for calculating the percentage chance of a Home Win is as followed

    (Home Team Overall Win % + Home Team Home Win % + Home Team Win % In Last 5 Games + Away Team Overall Loss % + Away Team Away Loss % + Away Team Loss % In Last 5 Games)

    ^ all divided by 6 to give an average percentage figure!

    To give an explanation for each part of that formula in case that isn't very clear:

    Home Team Overall Win % = Percentage of games that Home Team has won in the league that season (so 3 wins out of 10 games = 30%)
    Home Team Home Win % = Percentage of games that Home Team has won when playing at home (so 2 wins out of 4 home games = 50%)
    Home Team Win % In Last 5 Games = Fairly self-explanatory (so 3 wins out of last 5 games = 60%)
    Away Team Overall Loss % = Percentage of games that Away Team has lost in the league that season (so 4 losses in 10 games) = 40%
    Away Team Away Loss % = Percentage of games that Away Team has lost when playing away (so 2 losses in 3 away games = 66.6%)
    Away Team Loss % In Last 5 Games = Fairly self-explanatory (so 1 loss in last 5 games = 20%)

    And then the above are divided by 6 to give an average figure. In this case, the average figure is 44.43%. This means that the % chance of a Home Win in the upcoming game is 44.43%!

    ------------------------------------
    ------------------------------------

    Now that I've explained the above formula, what I want to achieve in Excel is to automate the above process if possible! While I can do it manually for each fixture, it would save me a lot of time if I could use the data I have to automate the process in Excel.

    So for example, on my 'Fixtures' sheet, once I've inserted 'Man Utd' in the Home Team column and 'Burnley' in the Away Team column, it would be great if the 'Home Win %' column would automatically fill using my above formula by somehow creating an Excel Formula that automatically looks up Man Utd and Burnley's results so far in the 'Results' sheet.

    I don't mind if it's a complicated process to get this done, I'm willing to learn how to do it/put the effort in to get the formulae set up.

    Is this possible in Excel? And if so, how is it done?

    Thank you very, very much to anyone who can help me do this if it's possible, I really appreciate any help I get!
    Last edited by pb90; 11-05-2014 at 02:33 PM.

  2. #2
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    I believe this can be achieved with some VBA programming, I'll try to post an example later.

  3. #3
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    Ok, this is a very rough approach as I have just started VBA basics. The list on the left is the team data with dates, wins, losses etc.

    On the right there is a drop-down list of all teams. Select a team and click the Process button. There is a macro assigned to the button that does the calculations of total wins, losses and draws for that team. The coding is very basic and unprofessional, but I suppose it is a good start and besides its my first working macro, created from scratch
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-02-2014
    Location
    London
    MS-Off Ver
    Excel For Mac 2011
    Posts
    10

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    Thank you very much for the help; it certainly seems like VBA programming is the way to go for this having looked at your example.

    I guess I'd better start learning VBA basics!

    So am I right in thinking that my best bet will be to use VBA programming to have a third sheet where all of the percentages for each team (four for each team: Overall Win %, Win % At Home, Win % Away, Win % In Last 5 games) are calculated by the click of a button, then have my Home/Draw/Away predictions on my original sheet, and have these calculated by using formulae that reference the sheet where the VBA programming will be?

    If I had all of that set up as above, would I be able to set the spreadsheet up so that if I typed 'Arsenal' in the home team slot and 'Burnley' in the away team slot, the sheet would automatically look up the VBA programming's % values for each team and calculate the odds I want automatically?

    Thanks for any more help you can give. Appreciate it!

  5. #5
    Registered User
    Join Date
    11-02-2014
    Location
    London
    MS-Off Ver
    Excel For Mac 2011
    Posts
    10

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    Okay, new help needed if possible to anyone reading!!

    I've written up a VBA code specifically for my spreadsheet, based on your VBA code above bmouse. I've written down the columns and values correctly, but for some reason Excel is telling me there are errors in this code. The errors seem to be wherever a line uses the Cells line. So, for example, there is an error in this line "If Cells(2, “A") = Cells(StartNumber, “K") Then".

    If you or anyone else good with VBA could take a look at this and see where I'm going wrong I'd really appreciate it! Thanks

    ----------

    Dim counterW As Integer
    Dim counterL As Integer
    Dim counterD As Integer
    Dim StartNumber As Integer
    Dim EndNumber As Integer

    EndNumber = 1000
    counterW = 0
    counterL = 0
    counterD = 0

    For StartNumber = 2 To EndNumber

    If Cells(2, “A") = Cells(StartNumber, “J") Then

    If Cells(StartNumber, “N") = "H" Then

    counterW = counterW + 1

    Else

    If Cells(StartNumber, “N") = "D" Then

    counterD = counterD + 1

    Else: counterL = counterL + 1
    End If
    End If
    End If

    Next StartNumber




    For StartNumber = 2 To EndNumber

    If Cells(2, “A") = Cells(StartNumber, “K") Then

    If Cells(StartNumber, “N") = "A" Then

    counterW = counterW + 1

    Else

    If Cells(StartNumber, “N") = "D" Then

    counterD = counterD + 1

    Else: counterL = counterL + 1


    End If
    End If
    End If

    Next StartNumber

    Cells(2, “C").Value = counterW
    Cells(2, “D").Value = counterD
    Cells(2, “E").Value = counterL

  6. #6
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    It looks solid, no visible mistakes, except there are 2 lines missing - 1st and last. The 1st line is Sub SubName () and the last line is End Sub, did you forget those or simply did not add to the post?

    If you want me to fiddle with it, you can post the entire book with the code, I'll see if I can get it working.

  7. #7
    Registered User
    Join Date
    11-02-2014
    Location
    London
    MS-Off Ver
    Excel For Mac 2011
    Posts
    10

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    That would be brilliant if you don't mind taking a look! Thank you so much for the help bmouse, appreciate it!

    The file is with this post.

    The sheet you want is the third sheet along, entitled 'E0'. The data is in a table to the right, and the macro button is to the left, just below where the data should end up if the macro is working.

    There are lots of other sheets but you don't need to worry about those! Should also note that in the relevant 'E0' sheet, each fixture has a lot more data with it than specified above, but the only relevant columns are J, K and N (Home Team, Away Team and Full Time Result).

    Thanks very much
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    After your 1st FOR command you use the RANGE parameter, and there is your problem. Re-write that line of code with the CELLS parameter as it is everywhere else and it should work.

  9. #9
    Registered User
    Join Date
    11-02-2014
    Location
    London
    MS-Off Ver
    Excel For Mac 2011
    Posts
    10

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    Oops. Changed that and corresponding code and it's working now, awesome.

    Thanks so much for your help.

    Final question: If I wanted all 20 teams listed out, and to be able to update all of their Win Records with the click of a button, am I right in thinking that I could do that with a single button by writing multiple Subroutines in that one Macro, altered slightly for each row the teams would be listed on?

    Thanks; also, I'm new to this forum, so if there's a common way to 'upvote' you or say thanks for being a big help that you'd appreciate let me know!

  10. #10
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Creating formula which auto looks up specific data & makes calculation based on that d

    I suppose you can write additional subroutines to do all teams with a single button press, perhaps not the most efficient way, but I believe if it works for 1 team, it should work for 20 as well.

    If you wish to thank people you can click Add reputation under their name, left side of any post. Also if you think the problem is solved, please mark the thread SOLVED, I think its on the top of the thread, right hand side.

    Glad I could help you out, and good luck

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Auto Populating based on specific data
    By Stechnical in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-08-2014, 01:10 AM
  2. Formula or macro for specific type data calculation
    By Amit1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-16-2013, 05:42 AM
  3. Need VBA to auto copy data from one sheet to specific on based of Staus
    By nadeemjadoon in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-04-2013, 12:25 PM
  4. auto fill time based on a when a specific cell has data entered
    By b16dlg in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-30-2012, 05:26 AM
  5. creating new sheets based on specific data
    By dfeld71 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1