Forum

VBA to select a sli...
 
Notifications
Clear all

VBA to select a slicer item when all possible slicer items are not yet available.

4 Posts
3 Users
0 Reactions
130 Views
(@kp4bnx)
Posts: 3
Active Member
Topic starter
 

I generate a daily workbook with 40 tabs filled with tables.  Once complete, I have VBA that goes through the tabs and selects certain slicer items or filters the data a certain way for presentation in daily meetings to hit the highlights.  A few tabs won't have their full list of standard slicer items until mid-week, if at all, so the VBA I have will crash when the missing slicer items aren't available.  Below the VBA has the full list of 15 slicer items, some weeks my actual data may be missing 1 or 2 lesser used items.  How can I fix the VBA, so it picks the slicer item I need regardless of whether all the items are available?

Sample file is attached.  Thank you.  

Sheets("Track Workhours").Select
With ActiveWorkbook.SlicerCaches("Adhoc_Activity")
.SlicerItems("Assist Analyst 1").Selected = True
.SlicerItems("Assist Analyst 2").Selected = False
.SlicerItems("Assist Mgmt Intern").Selected = False
.SlicerItems("Assist Senior Analyst").Selected = False
.SlicerItems("Assist Team Project").Selected = False
.SlicerItems("Collection Mail Run").Selected = False
.SlicerItems("Driver Training").Selected = False
.SlicerItems("In-Office Training").Selected = False
.SlicerItems("Interoffice Hub").Selected = False
.SlicerItems("Loan to another facility").Selected = False
.SlicerItems("Misc. - Explanation Required!").Selected = False
.SlicerItems("New Hire Training").Selected = False
.SlicerItems("Out-of-Office Training").Selected = False
.SlicerItems("Priority Mail - Express Run").Selected = False
.SlicerItems("Sunday Work Hours").Selected = False
End With
  

Kyle Francis

 
Posted : 28/08/2024 12:15 pm
(@keebellah)
Posts: 373
Reputable Member
 

Hi Kyle,

First tell us which Excel version you're using

Second, a copy of your file as sample removing private/sensitive data?

 
Posted : 29/08/2024 2:16 am
(@debaser)
Posts: 838
Member Moderator
 

Will the item you want to select always be present? If not, what do you want to happen?

 
Posted : 29/08/2024 3:52 am
(@kp4bnx)
Posts: 3
Active Member
Topic starter
 

Excel Version Microsoft 365 MSO (Version 2405 Build 16.0.17628.20006) 64-bit

Yes, the desired slicer item is always present.

Thank you.  

 
Posted : 30/08/2024 6:39 am
Share: