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
Bookmarks