Item could not be found in the OLAP cube when using a variable

Ellemieke

New Member
Joined
Oct 13, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I've got a workbook containing several pivot tables. I try to build a macro, so I can update outlook versions for all the tables at the same time. I have declared the outlook as a variable and inserted it into the code where the hard coded outlook used to be, but when I run the code, I get the error 'Item could not be found in the OLAP cube'. This is the code I've got:

Dim stroutlook As String
stroutlook = Range("S7")


ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"[Forecast Type].[Forecast Type].[Forecast Type Level 1]").VisibleItemsList = _
Array("")
ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"[Forecast Type].[Forecast Type].[Forecast Type Level 2]").VisibleItemsList = _
Array("")
ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"[Forecast Type].[Forecast Type].[Forecast Type Level 3]").VisibleItemsList = _
Array( _
"[Forecast Type].[Forecast Type].[Forecast Type Level 3].& [ " & stroutlook & " ] &[4022]&[4000]" _
)

Hardcoding the outlook to "OUTLOOK_2022_10" does work. What am I missing here?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You appear to have spaces in there (before/after the square brackets) that probably shouldn't be there, but you also haven't specified the sheet for the Range("S7") property, which is rarely a good idea.
 
Upvote 0
Solution
Yes! That is the solution. I thought that spaces didn't really matter. Apparently they do. Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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