Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim subAddressParts As Variant
Dim destSheetName As String, destColumn As Long, currentRow As Long
Dim findCell As Range
subAddressParts = Split(Target.SubAddress, "!")
If UBound(subAddressParts) = 1 Then
'Link refers to a Sheet!Cell
destSheetName = Replace(subAddressParts(0), "'", "")
destColumn = Range(subAddressParts(1)).Column
currentRow = Range(subAddressParts(1)).Row
Else
'Link refers to a defined name
destSheetName = Application.Range(Target.SubAddress).Worksheet.Name
destColumn = Application.Range(Target.SubAddress).Column
currentRow = Application.Range(Target.SubAddress).Row
End If
With Worksheets(destSheetName)
Set findCell = .Columns(destColumn).Find(What:=Target.TextToDisplay, After:=.Cells(1, destColumn), _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
End With
If Not findCell Is Nothing Then
If findCell.Row <> currentRow Then
'The row has changed so change the hyperlink's subAddress and select the found cell
Target.SubAddress = "'" & destSheetName & "'!" & Cells(findCell.Row, destColumn).Address(False, False)
Application.EnableEvents = False
findCell.Worksheet.Activate
findCell.Select
Application.EnableEvents = True
End If
Else
MsgBox "Hyperlink text '" & Target.TextToDisplay & "' not found in column " & Split(Cells(1, destColumn).Address(True, False), "$")(0) & " of worksheet " & destSheetName
End If
End Sub