Filtering Slicer based on cell value

rcarmichael

New Member
Joined
Aug 10, 2012
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Good morning all,
I have already searched on this and other forums for where I'm going wrong, but nothing I've found has helped...
I am trying to filter a year-based slicer from the values in two cells. The code I've got so far works if &[Year1] is changed to &[2022] etc., but trying to pull in the actual cell value from A3 or A6 respectively throws an error.
The code I have so far is:
Sub Sales_Overview()
'
' Sales_Overview Macro
'

'
Dim Year1 As Long
Dim Year2 As Long

Year1 = Worksheets("Sales Overview").Cells(3, "A").Value
Year2 = Worksheets("Sales Overview").Cells(6, "A").Value


ActiveWorkbook.SlicerCaches("Slicer_Calendar").VisibleSlicerItemsList = Array( _
_
"[Date].[Calendar].[Year].&[Year1]", "[Date].[Calendar].[Year].&[Year2]")

End Sub
Any assistance is greatly appreciated,
Sincere regards,
Ryan
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
In addition, it doesn't NEED to be the slicer, it can instead be the OLAP Pivot Table directly:
VBA Code:
    ActiveSheet.PivotTables("Pivot").PivotFields("[Date].[Year].[Year]"). _
        VisibleItemsList = Array("[Date].[Year].&[[COLOR=rgb(226, 80, 65)]2021[/COLOR]]", "[Date].[Year].&[[COLOR=rgb(226, 80, 65)]2022[/COLOR]]")
But the principle is the same... how do I get the Year# Variables in there?
Sincere regards,
Ryan
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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