|
Home > Pivot > Format > Hyperlinks Pivot Table Hyperlink ExamplesCreate clickable "hyperlinks" in an Excel pivot table. The cells contain website URLs, email address, or worksheet cell references, formatted with underlined blue font. Select a "hyperlink" cell, and a worksheet macro automatically takes you to that location. |

Hyperlinks won't automatically appear in a pivot table, even if there are hyperlinks in the source data.
In this video, you'll see how to create fake hyperlinks in a pivot table, by using a few lines of Excel VBA code, and cell formatting.
The code is shown below the video, and there are sample files that you can download.
When you create a pivot table from Excel data, there might be valid hyperlinks in one or more columns of your source data table. Unfortunately, those hyperlinks will NOT appear in a pivot table that’s built from that data.
If hyperlink data is added to a pivot table, it is affected by the following limitations:

Fortunately, there’s a workaround that you can use, to create fake clickable hyperlinks in a pivot table. There are two main steps for this technique:
Before you use this clickable pivot table hyperlink workaround, there are a couple of things to keep in mind:

Before you add the macro code, follow these steps to format the hyperlink cells in the pivot table.
To create fake hyperlinks in a pivot table, you'll use a few lines of code on the worksheet's code module.
There are two macros below, and there's a sample Excel file for each macro.
The following code will follow hyperlinks for one specific pivot field in a pivot table.
Copy the code below, and paste it onto the worksheet code module, on the sheet where your pivot table is located. (The code is also in the sample file)
In the code, change the field name to match your pivot field name.
Tip: To get to that code module, right-click the sheet tab, then click View Code.
Private Sub Worksheet_SelectionChange _
(ByVal Target As Range)
Dim selPF As PivotField
Dim strField As String
Dim strAdd As String
Dim myVal As String
strField = "Site"
On Error Resume Next
Set selPF = Target.PivotField
If Not selPF Is Nothing And _
selPF.Name = strField Then
myVal = Target.Value
If InStr(1, myVal, "@") > 0 Then
strAdd = "mailto:"
End If
'2024-01-12 -go to worksheet cell
If InStr(1, myVal, "!") > 0 Then
strAdd = "#"
End If
ThisWorkbook.FollowHyperlink _
Address:=strAdd & myVal, _
NewWindow:=True
End If
End Sub
The following code will follow hyperlinks for two specific pivot fields in a pivot table.
Copy the code below, and paste it onto the worksheet code module, on the sheet where your pivot table is located. (The code is also in the sample file)
In the code, change the two field names to match your pivot field names.
Tip: To get to that code module, right-click the sheet tab, then click View Code.
Private Sub Worksheet_SelectionChange _
(ByVal Target As Range)
'code for 2 pivot fields
Dim selPF As PivotField
Dim strField As String
Dim strField2 As String
Dim strAdd As String
Dim myVal As String
strField = "Site"
strField2 = "Site2"
On Error Resume Next
Set selPF = Target.PivotField
If Not selPF Is Nothing Then
If selPF.Name = strField _
Or selPF.Name = strField2 Then
myVal = Target.Value
If InStr(1, myVal, "@") > 0 Then
strAdd = "mailto:"
End If
If InStr(1, myVal, "!") > 0 Then
strAdd = "#"
End If
ThisWorkbook.FollowHyperlink _
Address:=strAdd & myVal, _
NewWindow:=True
End If
End If
End Sub
After you download and unzip one of the sample files, copy the code, and paste it into your own workbook. (Paste it onto the Worksheet code module, where your pivot table is located.
Don't miss my monthly Excel newsletter! You'll get quick tips, article links, and a bit of fun. Add your email, and click Sign Up.
Next, when you get my reply, click the Confirm button. I add this step to protect you from spam!
Last updated: September 17, 2024 11:43 AM