Here is the code I’m working with. The only part not working is where it selects the previous date (date minus one).
Private Sub Workbook_Open()
Dim ws As Worksheet
Dim cacheIndex As Integer
Dim itemIndex As Integer
Dim mostRecentDate As Date
Dim mostRecentSlicerItem As slicerItem
Dim slicerCache As slicerCache
Dim slicerItem As slicerItem
‘ Activate the "Home" sheet
ThisWorkbook Sheets ("Home") .Activate
‘ Store the most recent date available (today's date minus 1 day)
mostRecentDate = Date - 1
‘ Loop through each slicer cache in the workbook
For Each slicerCache In ThisWorkbook.SlicerCaches
‘ Clear all manual filters in the slicer cache
slicerCache.ClearManualFilter
‘ Loop through each slicer item in the current slicer cache
For Each slicerItem In slicerCache. SlicerItems
If IsDate(slicerItem.Name) And Format(slicerItem.Name, "[$-en-US]d-mmmm;@") = Format(slicerItem.Name, "[$-en-US]d-mmmm;@") Then
If DateValue(slicerItem. Name) › mostRecentDate Then
mostRecentDate = DateValue(slicerItem.Name)
Set mostRecentSlicerItem = slicerItem
End If
End If
Next slicerItem
‘ Determine the most recent date in the slicer cache For Each slicerItem In slicerCache.SlicerItems
If IsDate(slicerItem.Name) And Format (slicerItem.Name, "[$-en-US]d-mmmm;@*) = Format(slicerItem. Name, "[$-en-US ]d-mmmm;@") Then
If DateValue (slicerItem. Name) › mostRecentDate Then
mostRecentDate = DateValue (slicerItem. Name)
Set mostRecentSlicerItem = slicerItem
End If
End If
Next slicerItem
‘ Select the most recent date in the slicer cache
If Not mostRecentSlicerItem Is Nothing Then
For Each slicerItem In slicerCache.SlicerItems
If slicerItem.Name = mostRecentSlicerItem. Name Then
slicerItem. Selected - True
Else
slicerItem.Selected = False
End If
Next slicerItem
End If
Next slicerCache
End Sub