Hi,
I am trying to create a userform that looks up an address on Google Maps, or directions between two addresses. I got the above error message when creating this code below:
The userform at the moment looks like this:
The macro should look for the address you typed from an already existing list (in column M) and open a hyperlink based on the postcode next to that address if a match is found (in column L). The "/" is highlighted (after Cells(r, 12).Value&) when the error comes up, I can't think what is wrong with the code though.
Please help if you can!
I am trying to create a userform that looks up an address on Google Maps, or directions between two addresses. I got the above error message when creating this code below:
Code:
Private Sub CommandButton1_Click()
Dim r As Integer, r2 As Integer, URL As String
Application.ScreenUpdating = False
TextBox2.Value = ""
On Error GoTo InvalidAddress:
Range("m:m").Select
Selection.Find(What:=TextBox1.Value, LookIn:=xlFormulas, lookat:=xlPart, MatchCase:=False).Activate
r = ActiveCell.Row
If TextBox2.Value = "" Then
URL = "https://www.google.co.uk/maps/place/" & Cells(r, 12).Value
ActiveWorkbook.FollowHyperlink Address:=URL, NewWindow:=True
Else
Selection.Find(What:=TextBox2.Value, LookIn:=xlFormulas, lookat:=xlPart, MatchCase:=False).Activate
r2 = ActiveCell.Row
URL = "https://www.google.co.uk/maps/dir/" & Cells(r, 12).Value&"/"&cells(r2,12).value
ActiveWorkbook.FollowHyperlink Address:=URL, NewWindow:=True
End If
Exit Sub
InvalidAddress:
Range("a1").Select
MsgBox "We can't find this address, please check your spelling or copy and paste from the Combined Address column", vbExclamation, "Error"
TextBox2.Value = ""
End Sub
The userform at the moment looks like this:
The macro should look for the address you typed from an already existing list (in column M) and open a hyperlink based on the postcode next to that address if a match is found (in column L). The "/" is highlighted (after Cells(r, 12).Value&) when the error comes up, I can't think what is wrong with the code though.
Please help if you can!