Reputation: 25
I am attempting to automate the pull of data from multiple pages of a website into a workbook. On one sheet titled Events
I have 3 columns, the third of which (column C) is where I want the data pulled from, in the format URL;http://frc-events.usfirst.org/2015/txsa/rankings
. I attempted to use the following code to go down my 108 rows, fetching all data:
Sub GetData()
For x = 1 To x = 108
ActiveWorkbook.Worksheets("Events").Select
ActiveWorkbook.Worksheets("Events").Activate
mystr = Cells(x, 3)
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = Cells(x, 2)
With ActiveSheet.QueryTables.Add(Connection:= _
mystr, Destination:=Range( _
"$A$1"))
.Name = "rankings"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next x
End Sub
Unfortunately, upon running it, nothing happens. I've attempted to isolate it, and by setting x to any single number, it will work and create a single sheet. When attempting the run the loop however, as I said, I don't get a result. Any suggestions would be very appreciated.
BONUS question:
I'm sure this wouldn't likely be too difficult, but if instead of creating individual sheets for each new import, I wanted the data from all web pages to go into the same sheet, how might I go about that? (All data will be in the same format, (that is to say, same number of columns, though the amount of rows differs from page to page.
Upvotes: 0
Views: 9995