+ Reply to Thread
Results 1 to 6 of 6

Slicer Not Recognizing Pivot Table

Hybrid View

  1. #1
    Registered User
    Join Date
    08-24-2012
    Location
    Chicago
    MS-Off Ver
    Excel 20013
    Posts
    55

    Slicer Not Recognizing Pivot Table

    Well, I'm 90% fixed with my other problem and something tells me this is simple so I'm going to give it a shot. I need to create a simple slicer for a pivot table. I am creating the pivot table via a macro (below). Even though Excel clearly shows a happy pivot table, the slicer stays gray until I just select a blank cell (which is useless for creating a slicer).

    So, I've attached the file, the code I'm using for the slicer and the code I'm using for the pivot table. Please let me know what obvious thing I've missed.


    Test.xlsx

    Sub slicer()
    Dim l As SlicerCaches
    Dim m As Slicers
    Dim n As Slicer
    
    Set l = ActiveWorkbook.SlicerCaches
    Set m = i.Add(ActiveSheet.PivotTables(1), "Target", "Business Unit").Slicers
    Set n = j.Add(ActiveSheet, , "Business Unit", "Target", 0, 0, 200, 200)
    Msgbox "Created Slicer"
    End Sub
    
    ' Region is the name field that we want to build the slicer for.
    ' My_Region is the name that has been assigned to the slicers object.
    Sub zzp1()
    
        Dim objTable As PivotTable, objField As PivotField
        Dim objPivotItem As PivotItem
    
        ActiveWorkbook.Sheets("Data").Select
        Range("A1").Select
        
        Set objTable = ActiveSheet.PivotTableWizard
        
        Set objField = objTable.PivotFields("Area")
        objField.Orientation = xlRowField
        
        Set objField = objTable.PivotFields("Business Unit")
        objField.Orientation = xlRowField
        
        Set objField = objTable.PivotFields("Completion Status")
        objField.Orientation = xlColumnField
        
        Set objField = objTable.PivotFields("Completion Status")
        objField.Orientation = xlDataField
        objField.Function = xlCount
        objField.NumberFormat = "#,##0"
        
        Set objField = objTable.PivotFields("Description")
        objField.Orientation = xlPageField
        
        Application.DisplayAlerts = True
     End Sub

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Slicer Not Recognizing Pivot Table

    your pivot table is an excel 2000 version because you used the wizard so you can't use a slicer with it-you should use the pivotcache's createpivottable method
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    08-24-2012
    Location
    Chicago
    MS-Off Ver
    Excel 20013
    Posts
    55

    Re: Slicer Not Recognizing Pivot Table

    Thanks. I will try that.

  4. #4
    Registered User
    Join Date
    08-24-2012
    Location
    Chicago
    MS-Off Ver
    Excel 20013
    Posts
    55

    Re: Slicer Not Recognizing Pivot Table

    Okay, I feel like I'm really close here. 3 different XL books say that I got this right but I keep getting a syntax error on the section marked in red. Any ideas why this is tanking?

    Sub PivotCache()
        Dim PTCache As PivotCache
        Dim PT As PivotTable
    
        Set PTCache = ActiveWorkbook.PivotCaches.Create( _
            SourceType:=xlDatabase
            SourceData:=Range("A1").CurrentRegion)
    
        Worksheets.Add
    
        Set PT = ActiveSheet.PivotTables.Add( _
            PivotCach:=PTCache, _
            TableDestination:=Range("A3"))
    
        With PT
            .PivotFields("Description").Orientation = xlPageField
            .PivotFields("Completion Status").Orientation = xlColumnField
            .PivotFields("Region").Orientation = xlRowField
            .PivotFields("Completion Status").Orientation = xlDataField
    
        .DisplayFieldCaptions = False
        End With
    End Sub

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Slicer Not Recognizing Pivot Table

    you're missing a comma and a line continuation character
    Set PTCache = ActiveWorkbook.PivotCaches.Create( _
            SourceType:=xlDatabase, _
            SourceData:=Range("A1").CurrentRegion)

  6. #6
    Registered User
    Join Date
    08-24-2012
    Location
    Chicago
    MS-Off Ver
    Excel 20013
    Posts
    55

    Re: Slicer Not Recognizing Pivot Table

    Actually, I got the same error message with the comma and line continuation. I found some alternate language and it works fine. Nevertheless, thanks for the help.

    Sub PivotTable()
        Dim PTCache As PivotCache
        Dim PT As PivotTable
    
        Set PTCache = ActiveWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:="'" & Activesheet.Name & "'!" & Range("A1").CurrentRegion.Address(true,true,xlR1C1))
    
        Worksheets.Add
    
        Set PT = ActiveSheet.PivotTables.Add( _
            PivotCache:=PTCache, _
            TableDestination:=Range("A3"))
    
        With PT
            .PivotFields("Description").Orientation = xlPageField
            .PivotFields("Completion Status").Orientation = xlColumnField
            .PivotFields("Region").Orientation = xlRowField
            .PivotFields("Completion Status").Orientation = xlDataField
    
        .DisplayFieldCaptions = False
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Protecting a pivot table sheet with a slicer
    By amphinomos in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-12-2013, 08:15 AM
  2. [SOLVED] Use slicer selections on one pivot table to filter another pivot table
    By porkandbeans in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2013, 12:30 AM
  3. Pivot Table (Slicer) Help
    By skate1991 in forum Excel General
    Replies: 0
    Last Post: 10-11-2012, 11:52 AM
  4. Disconnect a pivot table from a slicer
    By LisaK in forum Excel General
    Replies: 5
    Last Post: 04-12-2012, 11:07 AM
  5. Pivot Table Slicer Limit?
    By zlehmann in forum Excel General
    Replies: 0
    Last Post: 11-21-2011, 12:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1