Hi All I have these codes
Code:
Sub CodeGrouping()
Dim OldBk As Workbook
Dim PivotRng As Range
Dim PivCache As PivotCache
Dim PC As PivotCache
Dim PT As PivotTable
Dim Src As Worksheet, Dst As Worksheet, Cd As Worksheet
Set Src = Worksheets("SBBillingExport")
Set Cd = Worksheets("Codes")
Set OldBk = ThisWorkbook
Src.Activate
'Delete all existing Named Ranges
'Dim NamedRng As Name
'For Each NamedRng In Names
'OldBk.Names(NamedRng.Name).Delete
'Next
'Src.Range("A1:Q1").Select
'Src.Range("A1:Q1").Range(Selection, Selection.End(xlDown)).Select
'Set PivotRng = Selection
'OldBk.Names.Add Name:="PivotDataRng", RefersToR1C1:="=OFFSET(SBBillingExport!R1C1,0,0,COUNT(SBBillingExport!C7)+1,17)"
'OldBk.Names.Add Name:="BillingData", RefersToR1C1:=Src.Range("A1:Q1").Range(Selection, Selection.End(xlDown))
FinalRow = Src.Cells(Rows.Count, 1).End(xlUp).Row
DataSht = ActiveSheet.Name
Sheets.Add
NewSht = ActiveSheet.Name
'ThisWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=Range("A1").CurrentArray).CreatePivotTable TableDestination:="R4C" & Range("A1").CurrentRegion
Set PivCache = OldBk.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=DataSht & "!R1C1:R" & FinalRow & "C17", Version:=6)
Set PT = PivCache.CreatePivotTable(Tabledestination:=NewSht & "!R3C1", TableName:="PivotTable1", DefaultVersion:=6)
'With PivCache
'.CreatePivotTable Tabledestination:=NewSht & "!R3C1", TableName:="PivotTable1", DefaultVersion:=6
'End With
'Sheets(NewSht).Select
'OldBk.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=DataSht & "!R1C1:R" & FinalRow & "C17", Version:=6).CreatePivotTable TableDestination:=NewSht & "!R3C1", TableName:="PivotTable1", DefaultVersion:=6
'Set PV = ActiveSheet.PivotTables("PivotTable1")
PT.AddFields RowFields:="Client ID", PageFields:="Code" ', ColumnFields:="Code"
For i = 1 To Cd.Cells(1, Cd.Columns.Count).End(xlToLeft).Column
PT.AddDataField Field:=PT.PivotFields("Code"), Function:=xlCount
Next i
For j = 1 To Cd.Cells(1, Cd.Columns.Count).End(xlToLeft).Column
ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems(j).Caption = Cd.Cells(1, j)
Next j
For k = 1 To Cd.Cells(1, Cd.Columns.Count).End(xlToLeft).Column
ActiveSheet.PivotTables("PivotTable1").PivotFields(k).EnableMultiplePageItems = True
Next k
PT.PivotFields("Client ID").ShowAllItems = True
PT.DataFields(1).NumberFormat = "0"
Src.PivotTables("PivotTable1").PivotFields("Client ID").RepeatLabels = True
ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Company Name")
.Orientation = xlRowField
.Position = 2
End With
Range("A4").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Client ID").ShowAllItems = True
ActiveSheet.PivotTables("PivotTable1").PivotFields("Code").CurrentPage = "(All)"
Src.PivotTables("PivotTable1").PivotFields("Client ID").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
Src.PivotTables("PivotTable1").PivotFields("Client ID").RepeatLabels = True
End Sub
Sub PPItem()
Dim Code As Worksheet
Set Code = Worksheets("Codes")
Cells(1, 1) = "Codes"
Worksheets("Sheet22").Activate
With Worksheets("Sheet21").PivotTables(1)
r = 2
For x = 1 To .PivotFields(11).PivotItems.Count
Cells(r, 1) = .PivotFields(11).PivotItems(x).Name
r = r + 1
Next
End With
For y = 1 To Worksheets("Sheet21").PivotTables(1).PivotFields(11).PivotItems.Count
With Sheets("Sheet21").PivotTables("PivotTable1").PivotFields(Code.Cells(1, y))
.PivotItems(y).Visible = True
End With
Next
End Sub
[code/]
I created multiple PivotTable Values from the same field list Item called code. However, I am unable to filter each value with different list of codes.