Iterate over slicer via VBA and select a single item each time

前端 未结 3 2032
不知归路
不知归路 2020-11-30 15:48

I have several slicers within a spreadhseet. I\'d like to be able to loop over one of these via VBA, and select every option one by one. The macro below seems fine to my ti

3条回答
  •  Happy的楠姐
    2020-11-30 16:33

    I tried the above solutions but can't get them to work. I kept getting a 1004 object not defined error; might be because I'm using the data model. In the end I cobbled together this solution which picks up the slicer values from a range and then calls another macro to save in pdf (which was my ultimate objective). Not elegant but effective.

    Sub looop()
    
    Dim rng As Range, cell As Range
    Set rng = Sheet1.Range("B4:B5")
    For Each cell In rng
    
    ActiveWorkbook.SlicerCaches("Slicer_MasterBrand").VisibleSlicerItemsList = Array("[Customer].[MasterBrand].&[" & cell.Value & "]")
    
    a_ExportPDF
    
    Next cell
        
    End Sub
    

提交回复
热议问题