Select first item in slicer with OLAP pivot source

Zenaida

New Member
Joined
May 23, 2017
Messages
6
Office Version
  1. 365
Platform
  1. Windows
How do I select the first item in either the slicer or the pivot table? This is a date field and both the pivot table and slicer are sorted by descending so the newest date is always listed first. The below code works if I always want to select October 27, 2020; however, I need the most recent date selected. Because of how I have my pivot table/slicer sorted, the newest date should always be listed first. Code that will either select the first item or select the newest date will work. The field is formatted as a date, not date/time.

VBA Code:
ActiveWorkbook.SlicerCaches("Slicer_Dates").VisibleSlicerItemsList = Array("[tblDates].[Dates].&[2020-10-27T00:00:00]")

I appreciate any assistance you can provide. Thank you.

----------------------------------------
Office 365 Business
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Figured out how to do it:

VBA Code:
Dim MyReportDate As String
Dim LocalMax As Date
Dim MyRange As Range

    Set MyRange = Worksheets("Pivot Tables").PivotTables("pvttblDates").PivotFields("[tblDates].[Dates].[Dates]").DataRange
    LocalMax = Application.WorksheetFunction.Max(MyRange)
    MyReportDate = Format(LocalMax, "yyyy-mm-dd")
    Sheets("Pivot Tables").PivotTables("pvttblDates").PivotFields("[tblDates].[Dates].[Dates]").VisibleItemsList = Array("[tblDates].[Dates].&[" & MyReportDate & "T00:00:00]")
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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