VBA Code to Search Google and Return the Link for First Result
Hello,
I am trying to pull data from a website and populate a spreadsheet, but my first goal is just going to be to automatically search google and return the link for the first result since Scrubbing a website will bring it's own set of challenges. I've got the following code which works for the search, but I am stuck on why it is actually searching "CONCATENATE(RC[3],"" "",RC[2],""White Pages""" instead of the respective cell data (i.e. First Name | Last Name | White Pages). Then I am wondering how I can return the link of the first google result.
PHP Code:
Sub SearchGoogle()
Dim chromePath As String
Dim search_string As String
Dim query As String
Dim LastRow As Long
Dim data As Range
Dim rowIndex As Long
Dim GoogleReturn As String
LastRow = Sheets("stats_all").Cells(Sheets("stats_all").Rows.Count, "A").End(xlUp).Row
Set DCM = Sheets("stats_all")
Sheets("stats_all").Select
Set data = Range("A1", DCM.Cells(DCM.Rows.Count, 1).End(xlUp))
rowIndex = 1
Do While rowIndex <= data.Rows.Count
If data.Cells(rowIndex, 9) = "" Then
query = "=CONCATENATE(RC[3],"" "",RC[2],""White Pages"")"
search_string = query
search_string = Replace(search_string, " ", "+")
chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Shell (chromePath & " -url http://google.com/search?q=" & search_string)
'INSERT CODE TO GRAB LINK FROM GOOGLE'
data.Cells(rowIndex, 9) = GoogleReturn
rowIndex = rowIndex + 1
Else
rowIndex = rowIndex + 1
End If
Loop
Bookmarks