Hi,
Could anyone advise me on possible reason for the compile error below?
I was looking for solution how to replace Pivot table filters by slicers, and intended to have particular values selected on these slicers. I asctually already had manually created the slicers there, so there was dual control over the Pivot.
I found the solution and made the Sub work on the downloaded testing file, but now I cannot make the same code work in my target file.
The message is "Compile error: A module is not a valid type".
The solution I found was second Sub on this link: http://www.databison.com/slicer-vba-code-create-change-or-modify-a-pivot-table-slicer-using-vba/.
The only thing I changed on that module was replacing "Region" with "CoCd" and "West" with "C046", to be able to run it on my macro file and my data, before I develop it further.
The red highlighted statement is the one which prompted the Compile error, I never got any further:
I tried to delete the manually created slicers with same name, deleted it on all three sheets which were using them. Still no luck.
Appreciate any help,
Alarix
Could anyone advise me on possible reason for the compile error below?
I was looking for solution how to replace Pivot table filters by slicers, and intended to have particular values selected on these slicers. I asctually already had manually created the slicers there, so there was dual control over the Pivot.
I found the solution and made the Sub work on the downloaded testing file, but now I cannot make the same code work in my target file.
The message is "Compile error: A module is not a valid type".
The solution I found was second Sub on this link: http://www.databison.com/slicer-vba-code-create-change-or-modify-a-pivot-table-slicer-using-vba/.
The only thing I changed on that module was replacing "Region" with "CoCd" and "West" with "C046", to be able to run it on my macro file and my data, before I develop it further.
The red highlighted statement is the one which prompted the Compile error, I never got any further:
Rich (BB code):
Sub turn_off_on_slicer_field()
Dim i As SlicerCaches
Dim j As Slicers
Dim k As Slicer
Set i = ActiveWorkbook.SlicerCaches
Set j = i.Add(ActiveSheet.PivotTables(1), "CoCd", "CoCd").Slicers
Set k = j.Add(ActiveSheet, , "CoCd", "CoCd", 0, 0, 200, 200)
i("CoCd").SlicerItems("C046").Selected = True
'You can also use
k.SlicerCache.SlicerItems("C028").Selected = False
'Or
k.SlicerCache.SlicerItems(1).Selected = False
MsgBox "Turned off C046"
i("CoCd").SlicerItems("C046").Selected = True
'Or
k.SlicerCache.SlicerItems("C046").Selected = True
MsgBox "Turned on C046"
End Sub
Appreciate any help,
Alarix
Last edited by a moderator: