I want to show the data source of a Pivot Table for transparency.
I did find a related post here: display Excel PivotTable Data Source as cellvalue
I get #NAME? error for the formula I used in cell F4: =PivotTableSource("PivotTable1")
I checked that my PivotTable name is PivotTable1.
Function PivotTableSource(myPivot As String) As String
Dim rawSource As String
Dim a1Source As String
Dim bracket As Long
Application.Volatile
rawSource = ActiveSheet.PivotTables(myPivot).SourceData
a1Source = Application.ConvertFormula(rawSource, xlR1C1, xlA1)
bracket = InStr(1, a1Source, "]")
PivotTableSource = "=" & Mid(a1Source, bracket + 1)
End Function
