title: With Excel VBA get web element if element is present, skip if not
body: <p>I'm rather new at scrubbing web pages, but am getting a hang of it. I've managed to successfully get data from a webpage with the follwing command:</p>
  
  <pre><code>sht.Range("b" &amp; RowCount).Value = .document.getElementById("PriceLabel").getElementsByTagName("span")(3).innerText
  sht.Range("c" &amp; RowCount).Value = .document.getElementById("QuantityInput").Value
  </code></pre>
  
  <p>My challange is that not all webpages i search have these elements, and so the script stops with Run-time error 424 - Object required.</p>
  
  <p>I've tried an On Error GoTo command, but that only works for the first incident, then stops on the second webpage with the missing elements.</p>
  
  <p>That code is:</p>
  
  <pre><code>Next_sku:
  Do
      RowCount = RowCount + 1
      SKU = sht.Range("a" &amp; RowCount).Value
  
      With ie
      .Visible = False
      .navigate "http://www.staples.no/search?keywords=" &amp; SKU
  
          Do While .Busy Or _
              .readyState &lt;&gt; 4
              DoEvents
          Loop
  
      sht.Range("b" &amp; RowCount).Value = .document.getElementById("PriceLabel").getElementsByTagName("span")(3).innerText
      sht.Range("c" &amp; RowCount).Value = .document.getElementById("QuantityInput").Value
      On Error GoTo Next_sku
  
      End With
  
  Loop While sht.Range("a" &amp; RowCount + 1).Value &lt;&gt; ""
  </code></pre>
  
  <p>Can anybody help me with a code that will either return a blank result, manual input such as f.eks "Does not exist" og simply skip ahead to the next command line if the element is noexistant. The most important thing is that the script doesn't stop.</p>
  
  <p>Thanks :-)</p>