Macro to add hyperlink with variables

jtf

New Member
Joined
Apr 13, 2010
Messages
10
Related to my macro in this thread...
I got everything working thanks to the help in that thread, except for the column to add hyperlinks. The link needs to have a variable which is found in column A.

If I were to type the formula, it would look like this:

Code:
=HYPERLINK("https://npapps.mywebsite.com/DsmWeb/do/application/sbs/customer/View?applicationId="&A2&"",A2)
But this fails in a macro because of the quotes.
I was given this as an option in the previous thread:

Code:
=HYPERLINK("https://npapps.mywebsite.com/DsmWeb/do/application/sbs/customer/View?applicationId="&Range("A2") & "," & Range("A2")&")"

But it returns this error message:
Compile error - expected list separator or )

Any suggestions?

Thanks,
Jeff (Win7, Excel 2007)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Do you need the quotes in the url? If so, you'll probably have to use chr(34). Other than that, the syntax is just slightly off, missing a parenthesis, comma or ampersand somewhere.
 
Upvote 0
Do you need the quotes in the url? If so, you'll probably have to use chr(34). Other than that, the syntax is just slightly off, missing a parenthesis, comma or ampersand somewhere.
No, the quotes are not part of the URL. They are there to tell excel to include the number in cell A2 as part of the URL.
 
Upvote 0
Whoever gave you the code was just including the parenthesis as part of the url text, so there is no close for the HYPERLINK code.

This should work


=HYPERLINK("https://npapps.mywebsite.com/DsmWeb/do/application/sbs/customer/View?applicationId=" & Range("A2") & "," & Range("A2"))</pre>
 
Upvote 0
Hmmm, trying that and I still get an error:
Compile Error: Expected End of Statement

and it highlights the https

I think it needs another quote, but that still doesn't work. I added the double quotes at the end (tried with a space and w/o) and it still gives the error.

..... " & Range("A2") & ""," & Range("A2"))
 
Upvote 0
I got it. I used the "record macro" function and then copied what it created. The correct code is this:
"=HYPERLINK(""https://npapps.mywebsite.com/DsmWeb/do/application/sbs/customer/View?applicationId=""&R[0]C[-29]&"""",R[0]C[-29])"

Thanks for the help :biggrin:
 
Last edited:
Upvote 0
Glad that works. I was going to suggest this code:

Code:
"=HYPERLINK(" & Chr(34) & "https://mywebsite.com/DsmWeb/do/application/sbs/customer/View?applicationId=" & Range("A2") & "," & Range("A2") & Chr(34)

The problem was just confusion with parenthesis and quotes because there were so many of them embedded in the string.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,245
Members
452,900
Latest member
LisaGo

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