Olap Pivot Table Vba Macro Help

nphadro

New Member
Joined
Apr 14, 2015
Messages
4
I have the code below that I got from another thread hear. It works great but I want to change my array. Currently I have to list each account number. Can I make it so that my array is linked to a name range. My name range can look like either of the Below. I want to filter my cube data in the pivot table to show just these accounts (but my list can be dynamic now that it's a name range.) The lists are right below the code I listed.

[TABLE="width: 74"]
<tbody>[TR]
[TD]Sub Filter_Cube_ItemListInCode()


myArray = Application.Transpose(TempArray)


Filter_Cube_PivotField _
pvtField:=ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("[Customer].[Customer Code].[Customer Code]"), _
varArrIn:=Array("[Customer].[Customer Code].&[10029-00]", _
"[Customer].[Customer Code].&[10069-00]", _
"[media_type].[All].[This Item Does Not Exist]", _
"[Customer].[Customer Code].&[10146-00]", _
"[media_type].[All].[Sunday Paper, Radio]", _
"[media_type].[All].[TV]")
End Sub


Private Function Filter_Cube_PivotField(pvtField As PivotField, _
varArrIn As Variant)
Dim varExists() As Variant
Dim i As Long, lCount As Long
On Error Resume Next
Application.ScreenUpdating = False
With pvtField
For i = LBound(varArrIn) To UBound(varArrIn)
.VisibleItemsList = Array(varArrIn(i))
If (varArrIn(i) = .VisibleItemsList(1)) Then
lCount = lCount + 1
ReDim Preserve varExists(lCount)
varExists(lCount) = varArrIn(i)
End If
Next
If lCount > 0 Then .VisibleItemsList = varExists
End With
End Function


[/TD]
[/TR]
</tbody>[/TABLE]



[TABLE="width: 287"]
<colgroup><col></colgroup><tbody>[TR]
[TD][Customer].[Customer Code].&[10029-00][/TD]
[/TR]
[TR]
[TD][Customer].[Customer Code].&[10058-00][/TD]
[/TR]
[TR]
[TD][Customer].[Customer Code].&[10069-00][/TD]
[/TR]
[TR]
[TD][Customer].[Customer Code].&[10079-01][/TD]
[/TR]
[TR]
[TD][Customer].[Customer Code].&[10146-00][/TD]
[/TR]
[TR]
[TD][Customer].[Customer Code].&[10175-00][/TD]
[/TR]
[TR]
[TD][Customer].[Customer Code].&[10182-00]

OR

[TABLE="width: 74"]
<colgroup><col></colgroup><tbody>[TR]
[TD]10029-00[/TD]
[/TR]
[TR]
[TD]10058-00[/TD]
[/TR]
[TR]
[TD]10069-00[/TD]
[/TR]
[TR]
[TD]10079-01[/TD]
[/TR]
[TR]
[TD]10146-00[/TD]
[/TR]
[TR]
[TD]10175-00[/TD]
[/TR]
[TR]
[TD]10182-00



[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,234
Messages
6,170,891
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