Question : Find Pivot Table's Name

Using VBA code how do i get the name of a certain pivot table so that I can apply a filter.  For example i have the following code that creates a bunch of 2 column pivot tables and I want apply a filter on one.  The problem is that each time the tables are created, excel gives them arbitrary names eg. PivotTable24, PivotTable48 etc.  How do i get the name that is shown when you right click the pivot table and Select PivotTableOptions?

Thanks,

Artie
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
Sub FreqTables()
  
Application.ScreenUpdating = False
 
 
'This Procedure creates 34 pivot tables
Dim PTCache As PivotCache
Dim Pt As PivotTable
Dim SummarySheet As Worksheet
Dim ItemName As String
Dim Row As Long, Col As Long, i As Long
 
Application.ScreenUpdating = False
 
'Delete Summary Sheet if it Exists
'On Error Resume Next
'Application.DisplayAlerts = False
'Sheets("Frequency_Tables").delete
'On Error GoTo 0
 
'Add summary sheet
Set SummarySheet = Worksheets.Add
ActiveSheet.Name = "Frequency_Tables"
 
'Create Pivot Cache
Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Sheets("Temp").Range("A1").CurrentRegion)
 
Row = 1
For i = 1 To 16
    For Col = 1 To 6 Step 5 '2 colums
        ItemName = Sheets("Temp").Cells(1, i)
        With Cells(Row, Col)
            .Value = ItemName
            .Font.Size = 16
            .ColumnWidth = 65
        End With
        
'Create Pivot table
Set Pt = ActiveSheet.PivotTables.Add(PivotCache:=PTCache, Tabledestination:=SummarySheet.Cells(Row + 1, Col))
 
'Add Fields
If Col = 1 Then 'Freq Tables
    With Pt.PivotFields(ItemName)
        .Orientation = xlDataField
        .Name = "Frequency"
        .Function = xlCount
    End With
    
    Else
    With Pt.PivotFields(ItemName)
        .Orientation = xlDataField
        .Name = "Percent"
        .Function = xlCount
        .Calculation = xlPercentOfColumn
        .NumberFormat = "0.0%"
        '.PivotFilters.xlValueisGreaterThan DataField := "Metropolitan Statistical Area/Metropolitan Division" Value1 := 9
        
    End With
    'Pt.PivotFields(ItemName).PivotFilters.Add
    End If
    
    Pt.PivotFields(ItemName).Orientation = xlRowField
    'PT.PivotFields("Applicant Race: 1").Orientation = xlColumnField
    Pt.TableStyle2 = "Pivotstylemedium2"
    Pt.DisplayFieldCaptions = False
    If Col = 6 Then
        'add data bars to the last column
        Pt.ColumnGrand = False
        End If
    Next Col
    
    Row = Sheets("Frequency_Tables").Range("A65536").End(xlUp).Row + 3
    Next i
 
    End Sub

Answer : Find Pivot Table's Name

Assuming the pivot table is in cell K1, you should use ...
1:
2:
3:
 
range("K1").PivotTable.Name
Random Solutions  
 
programming4us programming4us