Creating Multiple Fields from the same PivotTable Field List Item But Filter But Filter Each Field Differently

Hashiru

Active Member
Joined
May 29, 2011
Messages
286
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.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,215,203
Messages
6,123,627
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top