Search code examples
excelslicersvba

Invalid Procedure Call Or Argument - Excel VBA Slicer Cache


The code below works fine on my computer with Excel 2013 and two other computers using Excel 2010 and 2016, but it gives the invalid procedure in the Slicer section (in bold below) for one of the users.

This is the first time I'm seeing this error from another user and have used this previously on other reports. I have no clue what might have caused this as the macro works fine on other computers and mine as well.

How do I fix this?

   Sheets("Scorecard").Select
**ActiveWorkbook.SlicerCaches("Slicer_Country").ClearManualFilter**
With ActiveWorkbook.SlicerCaches("Slicer_Resourcing_Team")
    .SlicerItems("RT1").Selected = True
    .SlicerItems("RT2").Selected = True
    .SlicerItems("RT3").Selected = True
    .SlicerItems("RT4").Selected = False
End With

Solution

  • The code below will work with 2 slicers named "Country" and "Resourcing_Team" (confirm in your workbook that this is the name of the slicers).

    Recommendation: try to avoid using ActiveWorkbook, and instead use fully qualified objects. I use in this code "SO_1.xlsm", modify it to your workbook's name).

    Code:

    Option Explicit
    
    Sub SlicersTst()
    
    Dim WB                      As Workbook
    Dim CountrySlcrCache        As SlicerCache
    Dim ResourcingSlcrCache     As SlicerCache
    
    Set WB = Workbooks("SO_1.xlsm")
    Set CountrySlcrCache = WB.SlicerCaches("Slicer_Country") '<-- set Slicer Cache to "Slicer_Country"      
    CountrySlcrCache.ClearManualFilter '<-- clear manual filters
    
    Set ResourcingSlcrCache = WB.SlicerCaches("Slicer_Resourcing_Team") '<-- set Slicer Cache to "Slicer_Resourcing_Team"
    With ResourcingSlcrCache
        .SlicerItems("RT1").Selected = True
        .SlicerItems("RT2").Selected = True
        .SlicerItems("RT3").Selected = True
        .SlicerItems("RT4").Selected = False
    End With
    
    End Sub