I am currently attempting to use a command button on a worksheet and VBA to import player statistic data to my worksheet from an official sports website on button click. The data that I am trying to copy is over 21 different webpages.
The format of the URL for the web pages is as follows: http://www.afl.com.au/stats/player-ratings/overall-standings#page/1 where the number at the very end of the URL varies between 1 and 21 to indicate which data sheet you're looking at.
See below for my code:
Sub Button1_Click()
Const WebAddress As String = "http://www.afl.com.au/stats/player-ratings/_
overall-standings#page/"
Dim qt As QueryTable
Dim PlayerRatings As Worksheet
Dim PageNumber As Integer
Dim RowPasteNumber As Integer
RowPasteNumber = 6
Set PlayerRatings = ActiveSheet
For PageNumber = 1 To 21
Set qt = PlayerRatings.QueryTables.Add(Connection:="URL;" & WebAddress & PageNumber,_
Destination:=Range("A" & RowPasteNumber))
qt.Refresh BackgroundQuery:=False
RowPasteNumber = RowPasteNumber + 41
Next PageNumber
End Sub
So my thinking was that I should be able to use a FOR loop which increments the PageNumber integer each time to cycle through the different webpages where the data is located then copy the data off that webpage and paste it 41 rows below the previous data in my worksheet.
The issue that I'm having is that the FOR loop completes 21 iterations (as it should) and each time it pastes the data 41 rows below the previous data (as it should) but it continues to copy the data on webpage 1 over and over again.
Can anybody see why my code may be doing this?
Your assistance is much appreciated.
Stephen