Creating URL links using a formula

Dan Morris

New Member
Joined
May 22, 2012
Messages
37
Office Version
  1. 365
Platform
  1. Windows
If
A1 = John
B1 = Bloggs<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
How do I make
C1 = a hyperlink to a file in the format "D:\files\John Bloggs" which I can then click to access John Blogg's files.<o:p></o:p>
<o:p></o:p>
I got as far as<o:p></o:p>
=CONCATENATE("D:\files\",A1," ",B1)<o:p></o:p>
but it wouldn't hyperlink to the file structure it had created<o:p></o:p>
<o:p></o:p>
Can you help? :confused:
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Will this work for you? Quick and dirty.

Code:
Sub Add_Hyperlink()
Dim Name
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-2],"" "",RC[-1])"
    Name = ActiveCell.Value
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=("D:\files\" & Name)
End Sub
 
Upvote 0
Hi Again

Is there a way to make this always CONCATENATE A1 and A2 rather than using the [-2] and [-1] so if new columns are added it's dynamic and doesn't need to re-run the macro?

Also is it possible to make the macro run automatically because if you cut and paste it down a column it just creates the same hyperlink in all the fields (if you see what I mean?)

Thank you. Dan
 
Upvote 0
Why not use the HYPERLINK function?

=HYPERLINK("D:\files\"&A1&" "&B1)
 
Upvote 0
Hi HOTPEPPER

Thank you for that - it still doesn't quite work, it seems to create a hyperlink for D:\files\ but doesn't seem to add the text from A1 and B1 - is there a space or something wrong in the equation?

Thank you for all your help.

Dan
 
Upvote 0
It works, it works, it works.
That's brilliant; thanks both for your brilliant advice and help.
Dan
 
Upvote 0
One more question... is there a way to make the result just display "file" rather than the hyperlink below it, ie: it just says "file" but hyperlinks to a file locations as per below?:confused:
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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