I have a list of hyperlinks in column C on sheet 1, and I want to pull data from each link and put the data for each link in separate worksheets which have already been created. All of the hyperlinks are to the same website...pro football reference... but each link is for a different NFL player. I want to pull the same data table for each player. I have been able to pull data from the first link and put it in sheet 2 as it should be, but I am very new to VBA and can't figure out how to create a loop to do this for each link in my list and to put it in the other sheets. Below is the code I currently have to get data from the first link:
Sub passingStats()
Dim x As Long, y As Long
Dim htm As Object
Set htm = CreateObject("htmlFile")
With CreateObject("msxml2.xmlhttp")
.Open "GET", Range("C2"), False
.send
htm.body.innerhtml = .responsetext
End With
With htm.getelementbyid("passing")
For x = 0 To .Rows.Length - 1
For y = 0 To .Rows(x).Cells.Length - 1
Sheets(2).Cells(x + 4, y + 1).Value = .Rows(x).Cells(y).innertext
Next y
Next x
End With
End Sub
Any help would be greatly appreciated.
The following shows using a loop.
N.B.
'
to stop this.Code:
Test links in sheet1:
Sample webpage:
Corresponding code write out: