Hello,
I have created a dashboard in Excel 2010 using pivot charts and slicers. What I want to do is to create a macro to apply the same autofilters as the user has selected on the dashboard with the slicers, and apply the same filters on the data source sheet. I have it working, except for when the user chooses "(blank)" on the dashboard slicer. When that's selected, the filters always exclude the blank values.
I'm not sure where else to go from here, and I can't find anything online about INCLUDING blanks...tons of stuff about excluding and deleting blanks though! Any guidance would be appreciated. I should note that the message box displays "(blank)" instead of "=".
Here is the VBA I'm using:
Sub SlicerArray(slicername As String, columnnum As Integer) Dim sC As SlicerCache, sI As SlicerItem, myArrayVar As Long ' counts number of items selected Set sC = ActiveWorkbook.SlicerCaches(slicername) ' "Slicer_Segment" For Each sI In sC.SlicerItems If sI.Selected = True Then myArrayVar = myArrayVar + 1 Else End If Next sI ' creates array; adds slicer's name values to array myArrayVar = myArrayVar - 1 Dim mySliceName() As String ReDim mySliceName(0 To myArrayVar) As String For Each sI In sC.SlicerItems If sI.Selected = True Then If sI.Name = "(blank)" Then mySliceName(sCCount) = "=" sCCount = sCCount + 1 Else mySliceName(sCCount) = sI.Name sCCount = sCCount + 1 End If Else End If Next sI For sCCount = LBound(mySliceName) To UBound(mySliceName) ' MsgBox "Array Element " & sCCount & " has values of " & mySliceName(sCCount) & "." Next sCCount ' filters on Data sheet Sheets("Data").Select ActiveSheet.Range("$A$1:$AD$688").AutoFilter Field:=columnnum, Criteria1:=mySliceName, Operator:=xlFilterValues End Sub