Excel VBA code that displays a 14 day weather forecast I am trying to see if anyone can help me in making this Excel VBA code a little faster in rendering the data from the weather site I am using.  Maybe instead of getting all 14 days it includes in the site, could I get help in getting just 10 days? Any help is much appreciated. Thanks!
Sub MiamiWeather()

   Dim HTTP As Object, HTML As Object, i As Integer, j As Integer
    
    
    Set HTML = CreateObject(&quot;HTMLFILE&quot;)
    Set HTTP = CreateObject(&quot;MSXML2.XMLHTTP&quot;)
    
    myURL = &quot;https://weather.com/weather/tenday/l/3881cd527264bc7c99b6b541473c0085e75aa026b6bd99658c56ad9bb55bd96e&quot;
    
    HTTP.Open &quot;GET&quot;, myURL, False
    HTTP.send
    
    HTML.body.innerHTML = HTTP.responseText
    
    Set objCollection = HTML.getElementsByTagName(&quot;p&quot;)
    i = 0
    
    Do While i &lt; objCollection.Length And j &lt; 20
        If objCollection(i).getAttribute(&quot;data-testid&quot;) = &quot;wxPhrase&quot; Then
            j = j + 1
            Range(&quot;A&quot; &amp; j) = objCollection(i).PreviousSibling.PreviousSibling.FirstChild.innerText
            Range(&quot;B&quot; &amp; j) = objCollection(i).PreviousSibling.FirstChild.innerText
      
        End If
        i = i + 1
    Loop
    
    Set HTML = Nothing
    Set HTTP = Nothing
End Sub
The real question here is how to get only the p tags with a data-testid with the value of wxPhrase. This can be done using querySelectorAll().

Document.querySelectorAll(&quot;p[data-testid='wxPhrase']&quot;)

See Document.querySelectorAll().
You will need to add a reference to the Microsoft HTML Object Library and declare you document variable as HTMLDocument.

Dim Document As HTMLDocument


Loading the values into an Array will offer you the best performance.  It will not make a noticeable difference if you return 10 days or all the days of the month.
Refactored Code
Sub MiamiWeather()
    Dim Data As Variant
    Data = MiamiWeatherData
    
    Range(&quot;A1:B1&quot;).Value = Array(&quot;Date&quot;, &quot;Tempature&quot;)
    Range(&quot;A2&quot;).Resize(UBound(Data), 2).Value = Data
    
End Sub

Function MiamiWeatherData()
    Const URL = &quot;https://weather.com/weather/tenday/l/3881cd527264bc7c99b6b541473c0085e75aa026b6bd99658c56ad9bb55bd96e&quot;
    Dim responseText As String
    With CreateObject(&quot;MSXML2.XMLHTTP&quot;)
        .Open &quot;GET&quot;, URL, False
        .send
        responseText = .responseText
    End With
    
    Dim Document As HTMLDocument
    Set Document = CreateObject(&quot;HTMLFILE&quot;)
    Document.body.innerHTML = responseText

    Dim Children As IHTMLDOMChildrenCollection
    Set Children = Document.querySelectorAll(&quot;p[data-testid='wxPhrase']&quot;)
    Dim Results As Variant
    ReDim Results(1 To Children.Length, 1 To 2)
    Dim r As Long
    
    For r = 0 To Children.Length - 1
        Results(r + 1, 1) = Children(r).PreviousSibling.PreviousSibling.FirstChild.innerText
        Results(r + 1, 2) = Children(r).PreviousSibling.FirstChild.innerText
    Next
    
    MiamiWeatherData = Results
End Function