I'm trying to scrape information about the aggregated 30-year fixed mortgage rate for the US using VBA in Excel. Here's what I have so far, but I can't figure out what I'm doing wrong:
Sub National_Average()
'
' National_Average Macro
' Record the national average mortgage rate from https://fred.stlouisfed.org/series/MORTGAGE30US
Dim ie As InternetExplorer
Dim htmlEle As IHTMLElement
Dim i As Integer
i = 1
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://fred.stlouisfed.org/series/MORTGAGE30US"
Application.Wait (Now + TimeValue("00:00:05"))
For Each htmlEle In ie.document.getElementsByClassName("series-meta-observation-value")
With Sheets("Demand")
.Range("F2").Value = htmlEle.getElementsByClassName("series-meta-observation-value").textContent
End With
Next
ie.Quit
End Sub
I know it's got something to do with my For Each section, specifically the Range("F2").Value portion. Help would be appreciated!
.Range("F2").Valueif you are expecting more. So you will need to add a counter and use.Range("F2").offset(lngCounter,0).valueI think it would just behtmlEle.textContent