I am new to VBA, and I figured that trying to code is the best way to code. Anyway, I am trying to code a macro that will get first URL of a Google search result, but I\'m getti
In the zero result case, H3 is empty so modify your code like this to handle this case
Set html = CreateObject("htmlfile")
html.body.innerhtml = XMLHTTP.ResponseText
Set objResultDiv = html.getelementbyid("rso")
**numb_H3 = objResultDiv.getElementsByTagName("H3").Length**
**If numb_H3 > 0 Then**
Set objH3 = objResultDiv.getElementsByTagName("H3")(0)
Set link = objH3.getElementsByTagName("a")(0)
str_text = Replace(link.innerhtml, "", "")
str_text = Replace(str_text, "", "")
Cells(i, 2) = str_text
Cells(i, 3) = link.href
**Else**
**End If**
DoEvents
Next