Hey, I have a data which is Type and Link, The link a and b which is from different type will connect to different file, so it is a hyperlink. To simplify it, I use pivot table. Here is the code I use to link my data to hyperlink in pivot table:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim selPF As PivotField
Dim selPF1 As PivotField
Dim rg As Range
Dim strField As String
Dim rgLinks As Range
Dim lMatch As Long
strField = "Link"
Set rgLinks = Sheets("sheet3").Range("Table1[Link]")
On Error Resume Next
Set selPF = Target.PivotField
If Not selPF Is Nothing Then
If PivotTables("PivotTable2").PivotField.PivotItems("'Basic Type'[All]") = Sheets("sheet3").Range("Table1[Basic Type]") Then
If selPF.Name = strField Then
lMatch = Application.Match(Target.Value, rgLinks, 0)
If lMatch > 0 Then ThisWorkbook.FollowHyperlink Address:=rgLinks.Cells(lMatch).Hyperlinks(1).Address, NewWindow:=True
End If
End If
End If
End Sub
Data:
Type Link
1 a
1 b
2 a
2 b
3 a
3 b
The problem is my a and b with different type are all link to a and b type 1. How should I modified the code so that it will compare with the original data 'type'?, if the type is same, then only link it.
Bookmarks