Synch slicers VBA - object defined error

sashapixie

Board Regular
Joined
Aug 29, 2013
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hello

I have two datasets:

Dataset 1ContractorSkill
Dataset 2ContractorProject

I have a slicer for both datasets for contractor and i have a slicer for skill.

What i want to do is when the skill slicer is selected which in turn updates the contractor column / slicer in the pivot table to then reflect that change in the second dataset which does not have skill.

I have been trying to use this original code from Mr Excel but i keep getting a 1004 object defined error on the line For Each SI1 In sc1.SlicerItems

VBA Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    'Declaring variables
    Dim sc1 As SlicerCache
    Dim sc2 As SlicerCache
    Dim SI1 As SlicerItem

    'These names come from Slicer Settings dialog box
    Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Contractor")
    Set sc2 = ThisWorkbook.SlicerCaches("Slicer_Contractor1")

    'make the macro faster
    Application.EnableEvents = False
    Application.ScreenUpdating = False

    'Clearing filters to mirror sc1
    sc2.ClearManualFilter

    'Getting error here
    For Each SI1 In sc1.SlicerItems
    sc2.SlicerItems(SI1.Name).Selected = SI1.Selected
    Next SI1

    'make the macro faster
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub

I have found so many forums with this solution but it seems to work for those and i cannot find anyone having the same error.

I would be really grateful for any help.

Thanks in advance.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Works for me.
What version of excel do you have?

I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Works for me.
What version of excel do you have?

I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Hi DanteAmor

Thanks for your reply. I have updated my account information.

I am using Office 365.
 
Upvote 0
:unsure:

I tried to reproduce the scenario and the code works. I attach my test file to see if it works for you.
Just click on any Data (Data1, Data2, Data...) inside the slicer and automatically the other slicer is filtered.

1671204918440.png



----------------
If you have problems with your file you can upload a copy for someone to review and see what the problem is or find some other solution.

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,338
Members
449,218
Latest member
Excel Master

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