Go Back   Sports Handicapping Forum > Welcome Forums > Main Street > Capping

Capping All handicapping, betting systems, spreadsheets, mathematics & quantitative technicapping.

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 08-08-2010, 10:56 PM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Excel Macro for NFL Data

Thought I posted this but obviously I haven't.

Web developers and programming veterans often consider visual basic and excel to be amateur. But I find it to be extremely powerful, and those that are inclined to deviate from what is used by the consensus for spite deprive themselves of one of the more considerably tractable programs available.

Here is the excel macro VB code to get NFL data from Statfox

Spoiler:
Sub NFLfromStatfox()
'
' Get NFL Date from Statfox -- Enter specified years in the appropriate variable definitions
'

'
On Error Resume Next
Dim Datenum As Integer
Dim Datestart As Integer
Dim sht As String
Dim i As Integer
Dim n As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Datenum = 2009 'This corresponds to the desired starting data that fits the StatFox linking structure
Datestart = 2000
For n = 0 To (Datenum - Datestart)

For i = 1 To Range("NFLteams").Rows.Count 'NFLteams refers to the Range of teams labeled in the workbook
sht = Range("NFLteams").Cells(i, 1).Value
Worksheets.Add().Name = sht & Datenum
Sheets(sht).Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.statfox.com/nfl/gamelog~season~" & Datenum & "~teamid~" & sht & ".htm", _
Destination:=Range("$A$1"))
.Name = sht & Datenum
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "4,7,8"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
With Range("A2", Cells(Rows.Count, 1).End(xlUp))
.SpecialCells(xlCellTypeBlanks, xlTextValues).EntireRow.Delete
End With
Next i
Datenum = Datenum - 1 'Count down or Count up from a given date
Next n
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


What you need to do before running is create a table with the names of each team according to the parameters that correspond to the web address, i.e. San Diego = San+Diego, Giants = NY+Giants

You can speed up the process by importing a team report or statistics table from the website and find all '" "' and replace with '+' (Find spaces and replace with +), go here and copy and paste or the more efficient way is to import through excel web service browser

NFL Preseason - Team Report

Then select all the teams in the table and define a name to the range, a brief survey of the code and one can see I named the range "NFLTeams"

That's it, run the code. Takes a while but gets the job done. The workbook will contain however many years worth of sheets for each team, all named with the same format, team and year (Arizona2009, Washington2004, NY+Jets2007, etc...)

All impertinent and superfluous data will be stripped, and if you scan the code you can probably figure out which command is used to strip the data.

Each sheet will have the date, opponent, score, line, total, ats results, total results, offense/defense - rushing yds, rypa, passing yards, pypc

A great way to learn VB is to record or macro and see the result, and use google
__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000

Last edited by uva3021; 08-08-2010 at 11:01 PM.
Reply With Quote
  #2  
Old 08-10-2010, 12:24 PM
Registered User
 
Join Date: May 2008
Location: State College, PA
Posts: 527
Rewards: 62
WoW I just got major wood!!! Where Brit????? Great macro UVA!! Thanks !!!
Reply With Quote
  #3  
Old 08-10-2010, 09:13 PM
Hall Of Fame '11
 
Join Date: Aug 2004
Location: Philadelphia
Posts: 35,968
Rewards: 475
UVA always giving guys wood
Reply With Quote
  #4  
Old 08-13-2010, 06:52 PM
Not the Original!
 
Join Date: Sep 2009
Location: Fl
Posts: 513
Rewards: 620
I like to consider myself geeky, but UVA you take the cake. Take that as a compliment please.
__________________
Absent is my middle name
Reply With Quote
  #5  
Old 11-06-2010, 09:09 AM
Registered User
 
Join Date: Dec 2009
Posts: 1
Rewards: 30
I have been looking for a long time for this kind of spreadsheet. Has anyone created such sheet that cares to share

Thanks
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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



All times are GMT -5. The time now is 05:46 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.