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]
[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]