crystalneedshelpplzthnx
Board Regular
- Joined
- Nov 24, 2017
- Messages
- 55
- Office Version
- 365
- Platform
- Windows
Hi,
I run a report 7 days a week and have a few slicers per page. I have the slicers linked, but I need to update two of the slicers everyday to the latest date and the latest week. I have tried several slicers after looking online:
When I manually select slicers I get this:
I would prefer to loop through all available selections until the date in the cell is found. The cell is on another tab, but can be hidden on same tab is necessary.
Also, where would I store the code. Is it possible to save in my Personal workbooks module?
Thank you
I run a report 7 days a week and have a few slicers per page. I have the slicers linked, but I need to update two of the slicers everyday to the latest date and the latest week. I have tried several slicers after looking online:
Code:
Sub Filter_PivotField()
Dim sSheetName As String
Dim sPivotName As String
Dim sFieldName As String
Dim sFilterCrit As String
Dim pi As PivotItem
sSheetName = "Sales Summary"
sPivotName = "Slicer_Day_of_Date"
'I'm not sure if this name is correct, I'm not sure what the code needs:
sFieldName = "Day of Date"
'I get subscript our of range error here:
sFilterCrit = ThisWorkbook.Worksheets("Chart Data").Range("p10").Value
With ThisWorkbook.Worksheets(sSheetName).PivotTables(sPivotName).PivotFields(sFieldName)
For Each pi In .PivotItems
If pi.Name <> sFilterCrit Then
pi.Visible = False
End If
Next pi
End With
End Sub
When I manually select slicers I get this:
Code:
Sub Macro1()
With ActiveWorkbook.SlicerCaches("Slicer_Day_of_Week")
.SlicerItems("3/3/2018").Selected = True
.SlicerItems("2/24/2018").Selected = False
.SlicerItems("2/17/2018").Selected = False
End With
With ActiveWorkbook.SlicerCaches("Slicer_Day_of_Date")
.SlicerItems("3/1/2018").Selected = True
.SlicerItems("2/28/2018").Selected = False
.SlicerItems("2/27/2018").Selected = False
.SlicerItems("2/26/2018").Selected = False
.SlicerItems("2/25/2018").Selected = False
.SlicerItems("2/24/2018").Selected = False
.SlicerItems("2/23/2018").Selected = False
.SlicerItems("2/22/2018").Selected = False
.SlicerItems("2/21/2018").Selected = False
.SlicerItems("2/20/2018").Selected = False
.SlicerItems("2/19/2018").Selected = False
.SlicerItems("2/18/2018").Selected = False
.SlicerItems("2/17/2018").Selected = False
.SlicerItems("2/16/2018").Selected = False
.SlicerItems("2/15/2018").Selected = False
.SlicerItems("2/14/2018").Selected = False
.SlicerItems("2/13/2018").Selected = False
.SlicerItems("2/12/2018").Selected = False
.SlicerItems("2/11/2018").Selected = False
End With
End Sub
I would prefer to loop through all available selections until the date in the cell is found. The cell is on another tab, but can be hidden on same tab is necessary.
Also, where would I store the code. Is it possible to save in my Personal workbooks module?
Thank you
Last edited: