Determine the Last Page Value of a URL

I have written a Web-scraping tool that searches a website and returns the matches from this particular website. Many pages will be returned. So i can extract all the pages i have used a loop in which i have placed the page numbers into a sheet / Column A so that these numbers (values) are used to go to the different web pages.

Is there a way to determine how many pages were fetched i.e Determine the last page ?

Currently i guess how many pages there may be, which works but would be better if i knew the exact number of web pages will need to be looped through

Dim i As Integer
Dim code As String
Dim LastRow As Long
Dim Input1 As String
Dim Input2 As String
Dim URLend As String     


 LastRow = Cells(Rows.Count, 1).End(xlUp).Row

  For i = 2 To LastRow

    code = Range("A" & i).Value               

     With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://www.blabla/blabla/in-'" & Input1 & "' + '" & 
     Input2 & "/list-" & code _
     & URLend, Destination:=Range("$A$1"))

    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True        

    End With

 Next i


    i = i + 1    

End Sub

1 answer

  • answered 2019-04-15 06:38 Solar Mike

    So, add a message to the status bar using something like:

    Application.StatusBar = "Last page was " & i