Compile Error trying to automatically update slicers

samst

Board Regular
Joined
Feb 12, 2003
Messages
71
Hi There Hoping someone can help troubleshoot my code
Getting this error:

Compile Error : Method or Data Error not Found

I'm using the the latest version of Excel 64 bit

The goal of the code is to take the date in cell A2 and then automatically select the corresponding date in the slicers that have a source name of "Week End" and the previous 5 dates

VBA Code:
Sub SelectSlicerValues() 
Dim ws As Worksheet 
Dim slicerCaches As SlicerCaches 
Dim slicerCache As SlicerCache 
Dim dateValue As Date 
Dim dateList As String  
Dim i As Integer      
Set ws = ActiveWorkbook.Worksheets("Sheet1")     
 If Not ws Is Nothing Then      
Set slicerCaches = ws.SlicerCaches              
If slicerCaches.Count > 0 Then          
dateValue = ws.Range("A2").Value         
 dateList = Format(dateValue - 6, "m/d/yyyy") & ":" & Format(dateValue, "m/d/yyyy")                      
For Each slicerCache In slicerCaches            
 If slicerCache.SourceName = "Week End" Then                 
 slicerCache.ClearManualFilter                  
slicerCache.VisibleSlicerItemsList = Array(dateList)             
End If          
Next slicerCache      
Else         
 MsgBox "This worksheet doesn't contain any slicers.", vbExclamation, "No Slicers Found"      
End If 
Else     
 MsgBox "Worksheet not found.", vbCritical, "Error" 
 End If
End Sub
 
Last edited by a moderator:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Slicercaches belong to the workbook, not a worksheet.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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