Let's start by saying that I've never done webscraping. It seems like it should be a fairly easy process, but I need to pull data from multiple websites. The url for my first location is http://waterdata.usgs.gov/nwis/dv?c...07&site_no=371435093134701&referred_module=sw
...except I need to automate changing the site number. I have an Excel file that lists all of the site numbers in a single column, so it seems like I should be able to cycle through those, but I've tried a few different types of loops and can't get anything to work. Here's my most recent (and kind of sad attempt):
Sub web_scrape()
Dim wb As Workbook, fil As String, StaID As String
Worksheets("USGS_Observation_Wells").Activate
For x = ActiveSheet.QueryTables.Count To 1 Step -1
ActiveSheet.QueryTables(x).Delete
Next x
For i = 2 To 456
StaID = Worksheets("USGS_Obersvation_Wells").Range(i, 19)
With ActiveSheet.QueryTables.Add(Connection:="URL;http://waterdata.usgs.gov/nwis/dv?cb_72019=on&format=rdb&begin_date=1949-01-01&end_date=2012-05-07&site_no=" + StaID + "&referred_module=sw", Destination:=Worksheets("USGS_Observation_Wells").Range("U1"))
.Refresh BackgroundQuery:=False
End With
Next i
End Sub
Not only does it not work, but it pastes to the same location in the spreadsheet every time. So part 2 of my question, how can I make it past to the first blank column?
...except I need to automate changing the site number. I have an Excel file that lists all of the site numbers in a single column, so it seems like I should be able to cycle through those, but I've tried a few different types of loops and can't get anything to work. Here's my most recent (and kind of sad attempt):
Sub web_scrape()
Dim wb As Workbook, fil As String, StaID As String
Worksheets("USGS_Observation_Wells").Activate
For x = ActiveSheet.QueryTables.Count To 1 Step -1
ActiveSheet.QueryTables(x).Delete
Next x
For i = 2 To 456
StaID = Worksheets("USGS_Obersvation_Wells").Range(i, 19)
With ActiveSheet.QueryTables.Add(Connection:="URL;http://waterdata.usgs.gov/nwis/dv?cb_72019=on&format=rdb&begin_date=1949-01-01&end_date=2012-05-07&site_no=" + StaID + "&referred_module=sw", Destination:=Worksheets("USGS_Observation_Wells").Range("U1"))
.Refresh BackgroundQuery:=False
End With
Next i
End Sub
Not only does it not work, but it pastes to the same location in the spreadsheet every time. So part 2 of my question, how can I make it past to the first blank column?