title: How to extract first Google search result URL?
body: <p>I have a large list of search queries in column A.
  Is there any code I can use in order to extract the first Google search result URL in column B?</p>
  
  <p>I have used the code below successfully but instead of extracting the first search result URL it gets the number of search results.
  Anyone can help me change the code as per my requirements?</p>
  
  <pre><code>Sub Gethits()
  Dim url As String, lastRow As Long
  Dim XMLHTTP As Object, html As Object, objResultDiv As Object, objH3 As 
  Object, link As Object
  Dim start_time As Date
  Dim end_time As Date
  Dim var As String
  Dim var1 As Object
  
  lastRow = Range("A" &amp; Rows.Count).End(xlUp).Row
  
  Dim cookie As String
  Dim result_cookie As String
  
  start_time = Time
  Debug.Print "start_time:" &amp; start_time
  
  For i = 2 To lastRow
  
      url = "https://www.google.com/search?q=" &amp; Cells(i, 1) &amp; "&amp;rnd=" &amp; WorksheetFunction.RandBetween(1, 10000)
  
      Set XMLHTTP = CreateObject("MSXML2.serverXMLHTTP")
      XMLHTTP.Open "GET", url, False
      XMLHTTP.setRequestHeader "Content-Type", "text/xml"
      XMLHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
      XMLHTTP.send
  
      Set html = CreateObject("htmlfile")
      html.body.innerHTML = XMLHTTP.ResponseText
      Set objResultDiv = html.getelementbyid("rso")
      Set var1 = html.getelementbyid("resultStats")
      Cells(i, 2).Value = var1.innerText
  
      DoEvents
  Next
  
  end_time = Time
  Debug.Print "end_time:" &amp; end_time
  
  Debug.Print "done" &amp; "Time taken : " &amp; DateDiff("n", start_time, end_time)
  MsgBox "done" &amp; "Time taken : " &amp; DateDiff("n", start_time, end_time)
  End Sub
  </code></pre>