Sub FindData()
Dim accountNumber As Range
Set accountNumber = Range(Range("A2"), Range("A2").End(xlDown))
Dim dataSet As QueryTable
For Each Value In accountNumber
Set dataSet = .QueryTables.Add( _
Connection:="URL;http://www.prad.org/CamaDisplay.aspx?OutputMode=Display&SearchType=RealEstate&ParcelID=" & Value, _
Destination:=ThisWorkbook.Worksheets(2).Range("A1"))
Next Value
With dataSet
.RefreshOnFileOpen = False
.WebFormatting = xlWebFormattingNone
.BackgroundQuery = True
.WebSelectionType = xlSpecifiedTables
.WebTables = "3"
End With
With Application
dataSet.Refresh BackgroundQuery:=False
End With
End Sub
The ultimate goal here is to pull data from the URL
and drop it into Worksheet(2)
. The values in accountNumber
go at the end of the URL
for each page to draw data from.
This is my first VBA script, and right off the bat, it's giving me an error on Sub FindData()
I have the table of accountNumbers. The URL for one account is the given URL with an accountNumber after the final =. I am trying to iterate through one webpage per accountNumber and extract from each.
QueryTables needs to be properly referenced. You can use a sheet qualifier like : Sheets("yourname").QueryTables or something. You can remove the dot too...
Look into my code and see if this helps. I added a lot of comments to help you understand better the way the whole thing works.
I hope it helps :)