Link to home
Start Free TrialLog in
Avatar of RWayneH
RWayneHFlag for United States of America

asked on

Pivot Table Top 10 not working.

How come when I try to reduce the pivot table to just show the top 10, it does not do anything?  Any Ideas.  It is the last line in the example code.

For some reason I did not have to declare my data source???  which is tbl_pivot.  In an old file I have, I had to declare the data source:
SrcRng = Right(ActiveWorkbook.Names("RePlanPivotTableRange").RefersToR1C1, Len(ActiveWorkbook.Names("RePlanPivotTableRange").RefersToR1C1) - 1)
   
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        SrcRng, Version:=xlPivotTableVersion12).CreatePivotTable _
        TableDestination:="Sheet1!R3C1", TableName:="PivotTable1", DefaultVersion _
        :=xlPivotTableVersion12

The last statement in this code was to only use the Top 10, but it is not doing it??  Any Ideas?  



    Sheets.Add.Name = "Sheet1"
    Sheets("Sheet1").Activate

    Range("A5").Select
    ActiveWorkbook.Worksheets("Chart").PivotTables("PivotTable1").PivotCache. _
        CreatePivotTable TableDestination:="Sheet1!R5C1", TableName:="PivotTable4" _
        , DefaultVersion:=6
    Sheets("Sheet1").Select
    Cells(5, 1).Select
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Material")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
        "PivotTable4").PivotFields("COGI $$"), "Sum of COGI $$", xlSum
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum of COGI $$")
        .Caption = "Count of COGI $$"
        .Function = xlCount
    End With
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Count of COGI $$").Caption _
        = "Occurrance"
    ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
        "PivotTable4").PivotFields("COGI $$"), "Sum of COGI $$", xlSum
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum of COGI $$").Caption = _
        "Cost"
    
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Cost")
        .NumberFormat = "$#,##0.00"
    End With
    Range("B6").Select
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Material").AutoSort _
        xlDescending, "Occurrance", ActiveSheet.PivotTables("PivotTable4"). _
        PivotColumnAxis.PivotLines(1), 1
    Range("B6").Select
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Material").PivotFilters. _
        Add2 Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable4"). _
        PivotFields("Occurrance"), Value1:=10
        
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Material").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Material").PivotFilters. _
    Add2 Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable4"). _
    PivotFields("Occurrance"), Value1:=10
        
        
        
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RWayneH
RWayneH
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial