Green Squirrel
New Member
- Joined
- Jan 9, 2021
- Messages
- 25
- Office Version
- 365
- Platform
- MacOS
This is my 1st post on this website so please be kind
I want to pull some table from a website to excel and show them in Excel tables. You might be wondering why I don't use Power Query. Well I'm a Mac user....
I've already managed to pull the table that I want but I just can't figure out how to put this data in an Excel table. Been working on this for days and I just don't succeed.
I want to pull some table from a website to excel and show them in Excel tables. You might be wondering why I don't use Power Query. Well I'm a Mac user....
I've already managed to pull the table that I want but I just can't figure out how to put this data in an Excel table. Been working on this for days and I just don't succeed.
VBA Code:
Public Sub importMatches()
Dim QT As QueryTable
Dim URL As String
URL = "https://www.soccerstats.com/matches.asp?matchday=6"
Set QT = Sheet1.QueryTables.Add( _
Connection:="URL;" & URL, _
Destination:=Sheet1.Range("B2"))
With QT
.RefreshStyle = xlOverwriteCells
.AdjustColumnWidth = False
.WebFormatting = xlNone
.WebSelectionType = xlSpecifiedTables
.WebTables = "7"
.BackgroundQuery = False
.Refresh
End With
' Set a reference to the result range
Dim qtResultRange As Range
Set qtResultRange = QT.ResultRange
' Define the column numbers to delete
Dim colsToDelete As Variant
colsToDelete = Array(2, 3, 5, 6, 8, 9, 10)
' Delete from end to beginning
Dim counter As Long
For counter = UBound(colsToDelete) To 0 Step -1
qtResultRange.Columns(colsToDelete(counter)).EntireColumn.Delete
Next counter
End Sub