vbaexcelloopsexcel-web-query

VBA QueryTables loops class reference


What I am trying to do is grab data form mutable URLs, at the same time using cells A1 to A10 as the last string of text on the URLs QueryTables.

This is code I have at the moment

Sub URL_Static_Query()
Dim i As Integer
   
   With ActiveSheet.QueryTables.Add(Connection:= _
      "URL;myURlocation=" & Range("a1"), _
         Destination:=Range("a1"))
   
      .BackgroundQuery = True
      .TablesOnlyFromHTML = True
      .Refresh BackgroundQuery:=False
      .SaveData = True
   End With
End Sub

Solution

  • Try this, it will write the data starting from column B below each other.

      Dim i As Long
      For i = 1 To 10
         With Sheet1.QueryTables.Add(Connection:="URL;myURlocation=" & Range("a" & i), _
            Destination:=sheet1.Range("b999999").End(xlUp).Offset(1))
    
            .BackgroundQuery = True
            .TablesOnlyFromHTML = True
            .Refresh BackgroundQuery:=False
            .SaveData = True
         End With
      Next i