Hello,
I have a macro to update data in different sheets of the same workbook by following the hyperlink.
It works perfectly for first hyperlink cell, however, for the rest; cursor moves from active hyperlink cell to a different cell when 'Selection.Hyperlinks(1).Follow' initiates the below-mentioned change event;
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
and it opens any random hyperlink.
I am unable to find the reason for this. Any help is appreciated.
===============================
Code to follow and open hyperlink:
=======================================
Code from the sheet where data is updated
========================================
Code from the main sheet where Hyperlinks are mentioned
========================================
Code from 'ThisWorkbook' module [from the sheet where data is updated]
I have a macro to update data in different sheets of the same workbook by following the hyperlink.
It works perfectly for first hyperlink cell, however, for the rest; cursor moves from active hyperlink cell to a different cell when 'Selection.Hyperlinks(1).Follow' initiates the below-mentioned change event;
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
and it opens any random hyperlink.
I am unable to find the reason for this. Any help is appreciated.
===============================
Code to follow and open hyperlink:
Code:
Sub TestFollowHyperlink()
ActiveCell.Offset(0, 16).Select
Selection.Hyperlinks(1).Follow
Call UpdateandBack
End Sub
-------------------------------
Sub UpdateandBack()
Range("B3").Select
'Code to update the details
'Below code to return to Hyperlink cell
ActiveSheet.Range("A1").Hyperlinks(1).Follow
Cells(ActiveWindow.RangeSelection.Row, 1).Select
ActiveCell.Offset(0, 3).Select
ActiveCell.Offset(1, 0).Select
Call TestFollowHyperlink
End Sub
=======================================
Code from the sheet where data is updated
Code:
Option Explicit
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim TargetIndex As String
TargetIndex = Target.Range.Row & "," & Target.Range.Column
'MsgBox TargetIndex
Sheets(1).Visible = True
Sheets(1).Activate
Sheets(2).Visible = False
End Sub
========================================
Code from the main sheet where Hyperlinks are mentioned
Code:
Option Explicit
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim TargetIndex As String
TargetIndex = Target.Range.Row & "," & Target.Range.Column
'MsgBox TargetIndex
Select Case TargetIndex
'Cell address
Case "11,20"
Sheets(2).Visible = True
Sheets(2).Activate
Case "14,20"
Sheets(3).Visible = True
Sheets(3).Activate
Case "17,20"
Sheets(4).Visible = True
Sheets(4).Activate
Case "20,20"
End Select
Sheets(1).Visible = False
End Sub
========================================
Code from 'ThisWorkbook' module [from the sheet where data is updated]
Code:
Option Explicit
Private Sub Worksheet_Activate()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Manifest" Then
sh.Visible = xlSheetHidden
End If
Next sh
End Sub