Diagnosing/Resolving SlicerCache Issue

wroze27

New Member
Joined
Apr 23, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
I have the following code which is meant to loop through 3 different slicers I have. The end goal is to create an individual sheet for each possible option using the three slicers and to place them in folders also created by the code.

For reasons I do not understand, I keep getting "Invalid procedure call or arguement" error on line "Set s = ActiveWorkbook.SlicerCaches("OutSalesPersonName 6")" I have double checked and I'm confident on the name of the slicer. Can someone please help me understand what I am doing wrong?

VBA Code:
Sub CreateFolders()
  Dim s As SlicerCache
  Dim c As SlicerCache
  Dim m As SlicerCache
  Dim sItem As SlicerItem
  Dim cItem As SlicerItem
  Dim mItem As SlicerItem
  Dim sPath As String
  Dim cPath As String
  Dim mPath As String

  ' Set the slicer cache for each slicer
  Set s = ActiveWorkbook.SlicerCaches("OutSalesPersonName 6")
  Set c = ActiveWorkbook.SlicerCaches("Customer Name 3")
  Set m = ActiveWorkbook.SlicerCaches("Mfr 5")

  ' Loop through each item in the "OutSalesPersonName" slicer
  For Each sItem In s.SlicerItems
    ' If the slicer item is selected, create a folder with its name
    If sItem.Selected = True Then
      sPath = "C:\Users\wrozelle\Desktop\Reports\OS Reviews\" & sItem.Name
      MkDir sPath
      
      ' Loop through each item in the "Customer Name" slicer
      For Each cItem In c.SlicerItems
        ' If the slicer item is selected, create a folder with its name within the previous folder
        If cItem.Selected = True Then
          cPath = sPath & "\" & cItem.Name
          MkDir cPath
          
          ' Loop through each item in the "mfr" slicer
          For Each mItem In m.SlicerItems
            ' If the slicer item is selected, save a copy of "SPA Utilization" to the folder
            If mItem.Selected = True Then
              mPath = cPath & "\" & mItem.Name & ".xlsx"
              ActiveWorkbook.Sheets("SPA Utilization").Copy
              ActiveWorkbook.SaveAs Filename:=mPath
              ActiveWorkbook.Close False
            End If
          Next mItem
        End If
      Next cItem
    End If
  Next sItem
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Does it work if you use:
VBA Code:
Set s = ActiveWorkbook.SlicerCaches("Slicer_OutSalesPersonName 6")
 
Upvote 0
I'd expect those to be prefixed with Slicer_ and have any spaces replaced with underscores.
 
Upvote 0
When you right click on the slicer and select slicer settings, have a look at the section 'Name to use in formulas:'
 
Upvote 0
Now, im having a new issue: now im getting application-defined or object-defined error on:

For Each sItem In s.SlicerItems
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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