Use stored string array as an array

Gimics

Board Regular
Joined
Jan 29, 2014
Messages
164
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm using a vba macro to store the selected items in an OLAP slicer and then update a second OLAP slicer. I found a great macro for storing the selected items as a string array, but can't figure out how to then use the string array in the formula for updating the second slicer.

This is the formula I've used to populate my string array (please ignore declaration of slicer variables; they are working):


Code:
Dim ar() As String
ReDim ar(UBound(scCY.VisibleSlicerItemsList) - 1)
For i = 0 To UBound(scCY.VisibleSlicerItemsList) - 1
    svalue = scCY.VisibleSlicerItemsList(i + 1)
    ar(i) = svalue
Next

This populates the ar variable with the following text:
ar(0) = [Calendar].[GL Month].&[GL-2016-01]
ar(1) = [Calendar].[GL Month].&[GL-2016-02]
ar(3) = [Calendar].[GL Month].&[GL-2016-03]

This variable is dynamic in length, dependent on how many slicer filters are selected.

To update the second slicer, the following code is required:

Code:
ActiveWorkbook.SlicerCaches("Slicer_GL_Month5").VisibleSlicerItemsList = Array ("[Calendar].[GL Month].&[GL-2015-01]", _
"[Calendar].[GL Month].&[GL-2015-02]", "[Calendar].[GL Month].&[GL-2015-03]"

How can I populate the array formula to update the second slicer so that it includes each value in the string array ar(n)?

Code:
[COLOR=#574123]ActiveWorkbook.SlicerCaches("Slicer_GL_Month5").VisibleSlicerItemsList = [/COLOR]Array (ar(0),ar(1),(ar(2),ar(n))

Thanks for your help!
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
My apologies - I had thought I tried just using:

Code:
ActiveWorkbook.SlicerCaches("Slicer_GL_Month5").VisibleSlicerItemsList = ar

and that it didn't work, but it I had type the code incorrectly. Using the statement above worked fine.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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