Query several internet pages with a loop

Gaston0327

New Member
Joined
Jul 1, 2012
Messages
2
Hi there,

I have the following macro which pulls several tables from an internet page.

Verb Macro
'
' Keyboard Shortcut: Ctrl+z
'
Sheets("Sheet5").Select
ActiveCell.Select
Sheets("Sheet5").Select
ActiveCell.Cells.Select
Selection.Delete Shift:=xlUp
ActiveCell.Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.verbs.cat/es/conjugacion/35", Destination:=Range("$A$1"))
.Name = "35"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "2,3,4,5,8,9"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With

End Sub

What I need to know is how to create a loop so I may change the number in the URL (i.e. 35 to 36, 37, etc) and insert the table results in diferent cells.

Thanks in advance for your help !
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

b.downey

Active Member
Joined
Oct 16, 2011
Messages
484
As requested

Code:
Option Explicit
Sub Process()
    Dim wb As Workbook
    Dim I As Integer
    
    Dim SheetNo As Integer
    
    Set wb = ThisWorkbook
    Selection.Delete Shift:=xlUp
    ActiveCell.Select
    
    SheetNo = 1
    For I = 35 To 37
        wb.Worksheets(SheetNo).Activate
        wb.Worksheets(SheetNo).Cells.Clear
        With ActiveSheet.QueryTables.Add(Connection:="URL;http://www.verbs.cat/es/conjugacion/" & I, Destination:=Range("$A$1"))
            .Name = "QueryTable: " & I
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "2,3,4,5,8,9"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh BackgroundQuery:=False
        End With
        SheetNo = SheetNo + 1
    Next I
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,467
Messages
5,636,449
Members
416,919
Latest member
twc2c

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top