Control Slicer with VBA

zodiaceuk

Board Regular
Joined
Nov 20, 2011
Messages
103
Hi All,

Is it possible to control a slicer with VBA please?

I need the slicer to look for specific weeks.
These weeks are in CELs A1:A5

Wk1, Wk2 etc

The slicers control a couple of pivot tables.
I'm looking to find the weeks that are listed only.

Is this possible please?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi All,

I almost got this working, just need help getting the range to work.

Code:
Public Sub Test ()
Dim WK1 as String
Dim Item as SlicerItem

WK1 = Sheets("Control").Range("E24:E28")

For Each Item in ThisWorkbook.SlicerCaches("Slicer_Week2").SlicerItems
If Item.Name = WK1 then
Item.Selected = True
Else 
Item.Selected = False
End If 
Next Item

End Sub

This is giving a run-time error "13" - Type mismatch on:
WK1 = Sheets("Control").Range("E24:E28")

I have tried replacing the : with a , this made no difference.

The macro works perfectly when I only use .Range("E24"), however I need to include a couple of CELs

((Week format have been changed to numbers only 01, 02 etc))

am I missing something silly?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,716
Members
452,995
Latest member
isldboy

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