Excel Hyperlink Help

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Open the vba editor, and double click on the sheet you want this code to auto run on.

In the first drop down select "Worksheet" and the second drop down select "Change"

Replace the code with this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LinkAddress As String
    LinkAddress = "http://www.mysite.com/id/" & Target.Value
    Target.Hyperlinks.Add Target, LinkAddress
End Sub
If you are ever going to have links like 011 or other leading zeros, make sure the cells are formatted as text.

This does it to every cell on the sheet where data is entered so you'll need to be more specific if you need other limitations.
 
Upvote 0
Ok, give this a go then

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LinkAddress As String
    If Intersect(Target, Range("B2:B18")) Is Nothing Then
    Else
        LinkAddress = "[URL]http://www.mysite.com/id/[/URL]" & Target.Value
        Target.Hyperlinks.Add Target, LinkAddress
    End If
End Sub
 
Upvote 0
Everything is almost working, except when I want to clear/delete the link in the cell, it gives me a run-time error '1004' application-defined or object-defined error.
 
Upvote 0
Doh, oversight on my part:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LinkAddress As String
    If Target.Value = "" Then
        Target.Hyperlinks.Delete
        Else
            If Intersect(Target, Range("B2:B18")) Is Nothing Then
            Else
            LinkAddress = "[URL]http://www.mysite.com/id/[/URL]" & Target.Value
            Target.Hyperlinks.Add Target, LinkAddress
            End If
        End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
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