Hi Guys,
I hope you can help. I require the VB to be able to select the latest week only of a filter applied to a powerpivot table after its weekly refresh.
Whilst searching I came across the code below that performs the task based upon a date criteria. I was hoping it would not be too difficult a task to modify for latest week?
I hope someone can help me find a solution.
Thanks,
Plex.
I hope you can help. I require the VB to be able to select the latest week only of a filter applied to a powerpivot table after its weekly refresh.
Whilst searching I came across the code below that performs the task based upon a date criteria. I was hoping it would not be too difficult a task to modify for latest week?
Code:
Sub MaxDatePivot()
Dim pfiPivFldItem As PivotItem
Dim dtmDate AsDate
With Worksheets("Sheet1").PivotTables(1)
.PivotCache.Refresh
.ClearAllFilters
With .RowRange
dtmDate = Evaluate("MAX(IF(ISNUMBER(" & .Address(0, 0) & ")," & .Address(0, 0) & ",))")
EndWith
ForEach pfiPivFldItem In .PivotFields("End Date").PivotItems
pfiPivFldItem.Visible = (CDate(pfiPivFldItem.Value) = CLng(dtmDate))
Next pfiPivFldItem
EndWith
EndSub
I hope someone can help me find a solution.
Thanks,
Plex.