Instant Hyperlink from Text

Little_Clubber

New Member
Joined
Nov 10, 2017
Messages
32
Hi all you wonderful people out there. I'm hoping one of you can help me slim down a spreadsheet.

The sheet we have has many columns of data, and for ease, one of those is a Hyperlink, based on another.
For Argument sake, let's say I put a value in A1.
In B1, I have the formula =HYPERLINK("F:\Quality\Start up\2020"&"\"&A1".pdf",A1)
So this creates a hyperlink to the pdf file with the same name, and displays the "friendly name" of the document, which is the exact same information as shown in cell A1.
So A1 and B1 show the same value, one is a hyperlink.

What I would prefer to do is type my data in A1 and upon pressing Tab, Excel automatically change it to the formula I need based on the data that was already entered.
Is this possible please?
Thank you
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
A VBA procedure can take care of that.
The code below determines if the changed cell is within column A. If that's the case, anything entered will be converted to the hyperlink formula.
The code goes into the worksheet module of the sheet to be affected. Right click on the sheet tab > View Code > paste code in main pane.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const cFormula As String = "=HYPERLINK(""F:\Quality\Start up\2020\@FILE@.pdf"", ""@FILE@"")"
    
    If Not Target.Count > 1 And Not Intersect(Target, Target.Parent.Columns("A")) Is Nothing Then
        Application.EnableEvents = False
        Target.Formula = Replace(cFormula, "@FILE@", Target.Value)
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Solution
In case you don't need a formula but a real hyperlink try this ...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Const cPath As String = "F:\Quality\Start up\2020\@FILE@"

    If Not Target.Count > 1 And Not Intersect(Target, Target.Parent.Columns("A")) Is Nothing Then
        Application.EnableEvents = False
        With Target.Parent.Hyperlinks.Add(Anchor:=Target, Address:=Replace(cPath, "@FILE@", Target.Value & ".pdf"))
            .TextToDisplay = Target.Value
            .ScreenTip = Target.Value & ".pdf"
        End With
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
A VBA procedure can take care of that.
The code below determines if the changed cell is within column A. If that's the case, anything entered will be converted to the hyperlink formula.
The code goes into the worksheet module of the sheet to be affected. Right click on the sheet tab > View Code > paste code in main pane.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   
    Const cFormula As String = "=HYPERLINK(""F:\Quality\Start up\2020\@FILE@.pdf"", ""@FILE@"")"
   
    If Not Target.Count > 1 And Not Intersect(Target, Target.Parent.Columns("A")) Is Nothing Then
        Application.EnableEvents = False
        Target.Formula = Replace(cFormula, "@FILE@", Target.Value)
        Application.EnableEvents = True
    End If
End Sub
Amazing! Thank you so much! Both of your suggested VBA codes do exactly what I need in terms of the hyperlink, thank you again.
I'm going to use the first one because should we change the folder structure at any point in time and move any existing documents, I can use Ctrl+H and change the path in the existing formulae to keep them working, which I wouldn't know how to do from your second VBA macro.
Thank you again!
 
Upvote 0
You are welcome and thanks for the feedback.

I'm going to use the first one because should we change the folder structure at any point in time and move any existing documents, I can use Ctrl+H and change the path in the existing formulae to keep them working, which I wouldn't know how to do from your second VBA macro.
The macro below would do that, although unlike Ctrl H you cannot edit individual hyperlinks, that would have to be done via the cell context menu.
This macro changes all hyperlinks on the same worksheet pointing to files in the same folder.

VBA Code:
Private Sub ChangePathOfHyperlinkedFiles()

    Const cPathOld As String = "F:\Quality\Start up\2020\"
    Const cPathNew As String = "F:\Quality\2020\ArchivedFiles\"

    Dim oHl As Hyperlink
    For Each oHl In ActiveSheet.Hyperlinks
        If StrComp(Left(oHl.Address, (InStrRev(oHl.Address, "\"))), cPathOld, vbTextCompare) = 0 Then
            oHl.Address = Replace(oHl.Address, cPathOld, cPathNew)
        End If
    Next oHl
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,971
Members
449,059
Latest member
oculus

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