I copied the code from this link Extract financial fundamental from Yahoo finance with excel
The code from ASH works to pull balance sheet data; however, when I change the ticker (like MSFT), it begins pulling in the wrong data.
- Why is it pulling in different data points than when I switch the ticker in the URL Link?
How can I go about correcting it?
Sub Yahoo_BS() Dim xmlHttp As Object Dim TR_col As Object, Tr As Object Dim TD_col As Object, Td As Object Dim row As Long, col As Long Set xmlHttp = CreateObject("MSXML2.XMLHTTP.6.0") myURL = "https://finance.yahoo.com/quote/SBUX/balance-sheet?p=SBUX" xmlHttp.Open "GET", myURL, False xmlHttp.setRequestHeader "Content-Type", "text/xml" xmlHttp.send Dim html As Object Set html = CreateObject("htmlfile") html.body.innerHTML = xmlHttp.responseText Dim tbl As Object Set tbl = html.getElementById("Pos(r)") row = 1 col = 1 Set TR_col = html.getElementsByTagName("TR") For Each Tr In TR_col Set TD_col = Tr.getElementsByTagName("TD") For Each Td In TD_col Cells(row, col) = Td.innerText col = col + 1 Next col = 1 row = row + 1 Next End Sub