数据透视表超链接&要显示的文字

时间:2015-05-13 12:55:28

标签: excel vba excel-vba

我正在使用excel 2013.需要帮助添加Text以使用Excel VBA在数据透视表中显示。 ?

Pivot table screenshot

所以在上面的数据透视表中,[HyperLink]应该显示[Invoice Num]而不是完整的超链接地址,也许使用"文本显示" ???

我使用VBA使用以下代码在数据透视表中创建超链接:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count = 1 Then
        On Error Resume Next
        ActiveWorkbook.FollowHyperlink _
            Address:=CStr(Target.Value), _
            NewWindow:=True
        On Error GoTo 0
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

以下是覆盖超链接列格式的代码示例:

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Dim cell As Range
    For Each cell In ActiveSheet.PivotTables(1).RowFields("Hyperlink").DataRange.Cells
        cell.NumberFormat = ";;;""" & cell.PivotCell.PivotRowLine.PivotLineCells.Item(cell.PivotField.Position - 1).Range.Value & """"
    Next cell

End Sub
相关问题