Excel Fox
04-30-2011, 11:55 PM
If you wish to change the hyperlink of a cell based on the address given within that cell, the following code will automatically update the hyperlink provided within that cell.
Code can be revised for any cell/range though I have used A1 as an example. Check the attachment for a working sample
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address(0, 0) = "A1" Then
Target.Hyperlinks.Delete
ActiveSheet.Hyperlinks.Add Anchor:=Target.Cells(1), Address:="", SubAddress:=Target.Value, TextToDisplay:=Target.Value
End If
End Sub
Code can be revised for any cell/range though I have used A1 as an example. Check the attachment for a working sample
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address(0, 0) = "A1" Then
Target.Hyperlinks.Delete
ActiveSheet.Hyperlinks.Add Anchor:=Target.Cells(1), Address:="", SubAddress:=Target.Value, TextToDisplay:=Target.Value
End If
End Sub