VBA - Loop through slicer but exclude blank

kialexander

New Member
Joined
Jan 11, 2018
Messages
2
Hi,

I am using the following code to loop through all items in a slicer and then do a set of actions:

Dim sI As SlicerItem, sI2 As SlicerItem, sC As SlicerCache


Set sC = ActiveWorkbook.SlicerCaches("Slicer_Rep_Name")


With sC


For Each sI In sC.SlicerItems


sC.ClearManualFilter


For Each sI2 In sC.SlicerItems


If sI.Name = sI2.Name Then sI2.Selected = True Else: sI2.Selected = False


Next


Is there anyway that I can get it to exclude (blank)?

Thanks,

Kirstie
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi

The example below shows how to reference blank items:

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim sc1 As SlicerCache, sc2 As SlicerCache, si1 As SlicerItem, blk$
Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Categories")
Set sc2 = ThisWorkbook.SlicerCaches(4)
blk = "(vazio)"                                         ' Portuguese
'blk = "(blank)"                                        ' English
Application.ScreenUpdating = False
Application.EnableEvents = False
sc2.ClearManualFilter
For Each si1 In sc1.SlicerItems
    sc2.SlicerItems(si1.Name).Selected = si1.Selected
Next
sc2.SlicerItems(blk).Selected = False                   ' blanks
MsgBox "Update Complete"
clean_up:
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub
err_handle:
    MsgBox Err.Description
    Resume clean_up
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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