VBA for automatic selection of Slicer on changing TABs.

samirdey

New Member
Joined
Dec 9, 2019
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am trying to get a vba for selecting slicer automatically while changing tab. I have recorded macro but it is not working. Also, I want the macro to work whenever the workbook is opened and the different TAB is selected. Below is the recorded macro:

Sub Test()
'
' Test Macro
'

'
Sheets("CCR").Select
With ActiveWorkbook.SlicerCaches("Slicer_Dept")
.SlicerItems("CCR").Selected = True
.SlicerItems("BUS").Selected = False
.SlicerItems("BUS TECH").Selected = False
.SlicerItems("RES CARE").Selected = False
.SlicerItems("TECH").Selected = False
.SlicerItems("").Selected = False
.SlicerItems(" ").Selected = False
.SlicerItems("(blank)").Selected = False
End With
Sheets("BUS").Select
With ActiveWorkbook.SlicerCaches("Slicer_Dept")
.SlicerItems("BUS").Selected = True
.SlicerItems("BUS TECH").Selected = False
.SlicerItems("CCR").Selected = False
.SlicerItems("RES CARE").Selected = False
.SlicerItems("TECH").Selected = False
.SlicerItems("").Selected = False
.SlicerItems(" ").Selected = False
.SlicerItems("(blank)").Selected = False
End With
Sheets("BUS TECH").Select
With ActiveWorkbook.SlicerCaches("Slicer_Dept")
.SlicerItems("BUS TECH").Selected = True
.SlicerItems("BUS").Selected = False
.SlicerItems("CCR").Selected = False
.SlicerItems("RES CARE").Selected = False
.SlicerItems("TECH").Selected = False
.SlicerItems("").Selected = False
.SlicerItems(" ").Selected = False
.SlicerItems("(blank)").Selected = False
End With
Sheets("TECH").Select
With ActiveWorkbook.SlicerCaches("Slicer_Dept")
.SlicerItems("TECH").Selected = True
.SlicerItems("BUS").Selected = False
.SlicerItems("BUS TECH").Selected = False
.SlicerItems("CCR").Selected = False
.SlicerItems("RES CARE").Selected = False
.SlicerItems("").Selected = False
.SlicerItems(" ").Selected = False
.SlicerItems("(blank)").Selected = False
End With
Sheets("RES CARE").Select
With ActiveWorkbook.SlicerCaches("Slicer_Dept")
.SlicerItems("RES CARE").Selected = True
.SlicerItems("BUS").Selected = False
.SlicerItems("BUS TECH").Selected = False
.SlicerItems("CCR").Selected = False
.SlicerItems("TECH").Selected = False
.SlicerItems("").Selected = False
.SlicerItems(" ").Selected = False
.SlicerItems("(blank)").Selected = False
End With
End Sub[/CODE]

Please help.
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Watch MrExcel Video

Forum statistics

Threads
1,127,422
Messages
5,624,699
Members
416,042
Latest member
Oden

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
Top