I try to get data from website through xmlhttp GET. Unfortunately table doesn't have a constant amount of columns in a row or rows in a column, because some cells are merged (I even had to change max amount of columns manually to 11 in the macro as 1st row has fewer columns).
I would like the output to go exactly as on the website.
Option Explicit
Public Sub GetTable()
Dim oDom As Object: Set oDom = CreateObject("htmlFile")
Dim x As Long, y As Long
Dim oRow As Object, oCell As Object
Dim vData As Variant
Dim link As String
link = "http://medicarestatistics.humanservices.gov.au/statistics/do.jsp?_PROGRAM=%2Fstatistics%2Fmbs_group_standard_report&DRILL=on&GROUP=Broad+Type+of+Service+%28BTOS%29&VAR=services&STAT=count&RPT_FMT=by+time+period+and+state&PTYPE=month&START_DT=201609&END_DT=201609"
y = 1: x = 1
With CreateObject("msxml2.xmlhttp")
.Open "GET", link, False
.Send
oDom.body.innerHtml = .responseText
End With
With oDom.getelementsbytagname("table")(0)
ReDim vData(1 To .Rows.Length, 1 To 11) '.Rows(1).Cells.Length)
For Each oRow In .Rows
For Each oCell In oRow.Cells
vData(x, y) = oCell.innerText
y = y + 1
Next oCell
y = 1
x = x + 1
Next oRow
End With
Sheets(1).Cells(1, 1).Resize(UBound(vData), UBound(vData, 2)).Value = vData
End Sub
colSpanattribute of each TD/TH element, and create a merged cell for any colSpan > 1