Adding Hyperlinks based on cell contents

KelvinLGW

New Member
Joined
Jul 1, 2016
Messages
15
Hi,

Below is an example of my excel table:

ABCDEFGHI
1
2\Users\klee3\Desktop\18DP ESO\3_Off Tool Wins
4
51.pdf
62.pdf
73.pdf
84.pdf
95.pdf
106.pdf

<tbody>
</tbody>


So in Cell C2 is a UNC path which I have a macro to retrieve (folder only).
In Cells G5 all the way to last row used is the document names.

What I need a code to do is to go through each cell from G5 to last cell that has a value in it (i.e. last row used) and create a hyperlink using C2 & "" & (G5 all the way to the last cell in range G used).

I'm sure it's an easy code, but for some reason I cannot figure it out.

Any help would be much appreciated.

Thanks,

Kelvin
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
=hyperlink($c$2 & g5,"LINK")

However it looks like your path is not correct since it doesn't end with a blackslash.
 
Upvote 0
Sorry I should have added that I wanted this done on VBA.

KelvinLGW,
Give this a try:
Perpa

Code:
Sub hyperLINKcreate()
    Dim nextRow As Integer, x As Integer
    Dim myLink As Hyperlink
    Dim strSubAddress As String
    Dim xOriginal As String
    Dim LastRow As Integer
    
    LastRow = Cells(Rows.Count, "G").End(xlUp).Row

    For x = 5 To LastRow
        Cells(x, 7).Activate
        xG = ActiveCell.Text
        xOriginal = ActiveCell.Value
    
        If xOriginal = "" Then GoTo mycell
        If IsNumeric(xG) Then GoTo mycell
            With ActiveSheet
                Set myLink = .Hyperlinks.Add(ActiveCell, .Cells(2, "C").Value & Application.PathSeparator & xG, xG)
            End With
            
        'End If not required where the "IF' is all inclusive as above
mycell:
    Next x

End Sub
 
Upvote 0
KelvinLGW,
Give this a try:
Perpa

Code:
Sub hyperLINKcreate()
    Dim nextRow As Integer, x As Integer
    Dim myLink As Hyperlink
    Dim strSubAddress As String
    Dim xOriginal As String
    Dim LastRow As Integer
    
    LastRow = Cells(Rows.Count, "G").End(xlUp).Row

    For x = 5 To LastRow
        Cells(x, 7).Activate
        xG = ActiveCell.Text
        xOriginal = ActiveCell.Value
    
        If xOriginal = "" Then GoTo mycell
        If IsNumeric(xG) Then GoTo mycell
            With ActiveSheet
                Set myLink = .Hyperlinks.Add(ActiveCell, .Cells(2, "C").Value & Application.PathSeparator & xG, xG)
            End With
            
        'End If not required where the "IF' is all inclusive as above
mycell:
    Next x

End Sub

KelvinLGW,
One slight change to the last 'WITH' statement:

Code:
[TABLE="width: 48"]
<tbody>[TR]
[TD="width: 64, bgcolor: transparent"][FONT=Calibri][SIZE=3][COLOR=#000000]With ActiveSheet[/COLOR][/SIZE][/FONT]
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][FONT=Calibri][SIZE=3][COLOR=#000000]Set myLink =  .Hyperlinks.Add(ActiveCell, .Cells(2, "C").Value &  Application.PathSeparator & xG)

End With[/COLOR][/SIZE][/FONT]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,814
Members
449,339
Latest member
Cap N

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