(VBA) OLAP query with multiple selection

Goan

New Member
Joined
Oct 14, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi,

I tried to find some information on this but my knowledge of VBA are extremely limited and I was not able to understand what I am doing wrong.

I have a Cube and I am trying to automate multiple selection on a field. The selection will be taken from a list.

The recorded code for multiple selection is the below:

Sub Macro1()

ActiveSheet.PivotTables("PivotTable2").PivotFields("[Game].[Game].[Game]").VisibleItemsList = Array("[Game].[Game].&[XYZ]", "[Game].[Game].&[ZYX]")

End Sub

I tried the below:

Sub Macro3()

str1 = "[Game].[Game].&[" & Worksheets("YYY").Range("O6") & "]"
str2 = str1 & """" & ", " & """[Game].[Game].&[" & Worksheets("YYY").Range("O7") & "]"

ActiveSheet.PivotTables("PivotTable2").PivotFields("[Game].[Game].[Game]").VisibleItemsList = Array("" & str2 & "")

End Sub

If I check the value of the str2 this looks correct but running the code gives me syntax error

I tried many things, can't post them all also to do not confuse further but another one, as example, was:

Sub Macro4()

str1 = "[Game].[Game].&[" & Worksheets("YYY").Range("O6") & "]"
str3 = "[Game].[Game].&[" & Worksheets("YYY").Range("O7") & "]"
str2 = str3 & """" & ", " & """" & str1

ActiveSheet.PivotTables("PivotTable2").PivotFields("[Game].[Game].[Game]").VisibleItemsList = Array("" & str2 & "")

End Sub

I tried removing or adding " here and there but still there is some errors.

If I try with just one string, that works:

Sub Macro4()

str1 = "[Game].[Game].&[" & Worksheets("YYY").Range("O6") & "]"

ActiveSheet.PivotTables("PivotTable2").PivotFields("[Game].[Game].[Game]").VisibleItemsList = Array("" & str1 & "")

End Sub

The part I am needing VBA to modify, in the original code, is "[Game].[Game].&[XYZ]", "[Game].[Game].&[ZYX]" as I would like that XYZ and ZYX (and eventually more) will be taken from a list, with a loop, as there will be a variable numbers of Game.

I think that the error may be in the ", " part but honestly I lost myself already long time ago and I am not really sure of what I am talking about.

Anyone is able to help?

Thank you very much for your time.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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