Loop through Slicer for Data Model Pivot Table

rilzniak

Active Member
Joined
Jul 20, 2012
Messages
288
Hey all,

I'm struggling with syntax here, and I'm sure it's something simple. I'm trying to loop through the slicer I have for a Pivot Table but I can't figure out how to change the second part of this statement so that it varies as I loop through the options and print out statements for reporting.

VBA Code:
    sLocCode= mWB.Worksheets(mSheet).Cells(i, 2).Value

    ActiveWorkbook.SlicerCaches("Slicer_Location_Code").VisibleSlicerItemsList = Array("[Quantity].[Location Code].&[09]")

The sLocCode comes from a different workbook and will replace the numbers in the square brackets - "09". Can someone help explain how can I re-write the second part of that statement to accept a variable so that I'm able to loop through the different location codes? The quotations are throwing me for a loop (<-- see what I did there?).

Thanks in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
<-- see what I did there?
:)

It would be:

Code:
 ActiveWorkbook.SlicerCaches("Slicer_Location_Code").VisibleSlicerItemsList = Array("[Quantity].[Location Code].&[" & sLocCOde & "]")
 
Upvote 1
Solution
:)

It would be:

Code:
 ActiveWorkbook.SlicerCaches("Slicer_Location_Code").VisibleSlicerItemsList = Array("[Quantity].[Location Code].&[" & sLocCOde & "]")
Sigh. That was so simple. I was trying to keep the original double quotations in the statement (like an idiot!). Might have to send myself home early today, that was just so poor on my part.

Thank you, Rory. A+
 
Upvote 0
Glad we could help. :)
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,107
Members
449,096
Latest member
provoking

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