Name of Pivot Table

C

ch

Hi All,

In VBA script when it is running, is there a way to select any cell on the
pivot table and then obtain the name of the pivot table so that I can
manipulate it ?

Thanks.
 
B

Bob Phillips

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Me.PivotTables("PivotTable1").TableRange2) Is
Nothing Then

MsgBox Target.Address & " is part of PivotTable1"
End If
End Sub
 
D

Debra Dalgleish

To get the name of the pivot table for the active cell:

'========================
Sub GetPTName()
Dim pt As PivotTable

On Error Resume Next
Set pt = ActiveCell.PivotTable

If pt Is Nothing Then
MsgBox "Active cell is not in a pivot table"
Else
MsgBox ActiveCell.PivotTable.Name
End If

Set pt = Nothing
End Sub
'=====================
 
C

ch

Thanks Debra, this works just fine.

Debra Dalgleish said:
To get the name of the pivot table for the active cell:

'========================
Sub GetPTName()
Dim pt As PivotTable

On Error Resume Next
Set pt = ActiveCell.PivotTable

If pt Is Nothing Then
MsgBox "Active cell is not in a pivot table"
Else
MsgBox ActiveCell.PivotTable.Name
End If

Set pt = Nothing
End Sub
'=====================



--
Debra Dalgleish
Contextures
www.contextures.com/tiptech.html
Blog: http://blog.contextures.com
 
Top