Excel Hyperlinks Issue

dblue42

New Member
Joined
Feb 3, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am importing a lot of survey data from various files into Excel, which gets pasted using the paste special Paste:=xlPasteAll command in VB. One of the columns is full of GPS co-ordinates, formatted as a Google maps link. Most of these are pasted correctly, but occasionally a large set of them get pasted as plain text with no link. I cannot find any reason for this, it appears to be entirely random; there is nothing wrong with the source data (which is a HTML file produced by the survey trolley, opened in Excel and then the various bits are then copied out of it automatically).

I want to run a sub that converts them back into maps links. I have tried the HYPERLINK function, which does what I want but I don't really want the formulas to remain; I just want the hyperlink itself. I cannot get Excel to copy and paste the result of HYPERLINK as HTML, unless I copy it into word first and then copy it back. I've tried various bits of VB code from around the web, but none of them seem to do what I want.

I want a method of replacing the GPS plain text with hyperlinks in the following format:
Code:
"https://maps.google.com/?q=" &"{GPS data from column A}" & "&iwloc=A&t=h&z=17"
, use that as the hyperlink and then display the GPS text from column A. (Formatted as code to prevent the forum turning the link into a hyperlink instead of displaying plain text).

I tried to use this code I found here, which I modified slightly with the variable 'TextToDisplay'. It did part of the job, in that it turned the text format google link into a hyperlink, but I couldn't get it to change the displayed text from the full web address to just the GPS address. The code also stops working sometimes, for reasons beyond my skill level (novice).

VBA Code:
Sub Convert_Hyperlink()
For Each x In Selection
ActiveSheet.Hyperlinks.Add Anchor:=x, Address:=x.Formula, TextToDisplay:=x.Value
Next x
End Sub

Thanks in advance,

Dan E

GPS sorting.xlsm
ABC
1GPSHyperlink FormulaFull google link
253.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
353.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
453.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
553.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
653.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
753.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
853.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
953.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
1053.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
1153.1380954, -4.272859853.1380954, -4.2728598https://maps.google.com/?q=53.1380954, -4.2728598&iwloc=A&t=h&z=17
1253.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1353.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1453.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1553.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1653.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1753.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1853.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
1953.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
2053.1380871, -4.272850153.1380871, -4.2728501https://maps.google.com/?q=53.1380871, -4.2728501&iwloc=A&t=h&z=17
2153.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2253.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2353.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2453.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2553.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2653.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2753.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2853.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
2953.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
3053.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
3153.1380786, -4.272842153.1380786, -4.2728421https://maps.google.com/?q=53.1380786, -4.2728421&iwloc=A&t=h&z=17
Sheet 1
Cell Formulas
RangeFormula
B2:B31B2=HYPERLINK("https://maps.google.com/?q="&A2&"&iwloc=A&t=h&z=17",A2)
C2:C31C2=TEXT("https://maps.google.com/?q="&B2&"&iwloc=A&t=h&z=17",B2)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi
I don't have Excel open in front of me to test this, but one thing that jumps out at me is that there is a space between the two coordinates. There shouldn't be a space in URLS, and so I wonder whether this is where the code starts to fall apart. Perhaps try:

VBA Code:
Sub Convert_Hyperlink()
    For Each x In Selection
        ActiveSheet.Hyperlinks.Add Anchor:=x, Address:=Replace(x.Value, " ", ""), TextToDisplay:=x.Value
    Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top