Dynamically Building VisibleItemsList

Hashiru

Active Member
Joined
May 29, 2011
Messages
286
Hi All,

I need to build a VisibleItemsList to be able to filter based on the Criteria that the PivotItems names Should begin with DC- but not DC-PLANNING. My idea so far is this:

(I) Build an array of values and
(II) use the array in the .VisibleItmesList

Here is the code I got so far.

Code:
Sub FilterThem()
Dim MyFilterArray() As String
Worksheets("Sheet4").Activate
With Worksheets("Sheet3").PivotTables("PivotTable8")
    c = 1
    For i = 1 To .PivotFields.Count
        r = 1
        Cells(r, c) = .PivotFields(i).Name
        For x = 1 To .PivotFields(i).PivotItems.Count
            If Mid(.PivotFields(i).PivotItems(x).Name, 36, 4) = "[DC-" And Not (Mid(.PivotFields(i).PivotItems(x).Name, 36, 12) = "[DC-PLANNING") Then
                ReDim Preserve MyFilterArray(d)
                MyFilterArray = .PivotFields(i).PivotItems(x).Name
            End If
        r = r + 1
        Next
    c = c + 1
    Next
End With
End Sub


Intended list should be able to look like this

Code:
Array( "[CSVFolderPivotTable].[FAIN].&[DC-04-0007]", "[CSVFolderPivotTable].[FAIN].&[DC-04-0008]", "[CSVFolderPivotTable].[FAIN].&[DC-05-0011]", "[CSVFolderPivotTable].[FAIN].&[DC-34-0002]", "[CSVFolderPivotTable].[FAIN].&[DC-44-X001]", "[CSVFolderPivotTable].[FAIN].&[DC-54-0002]", "[CSVFolderPivotTable].[FAIN].&[DC-34-0002]", "", "[CSVFolderPivotTable].[FAIN].&[DC-57-X007]", "", "", "[CSVFolderPivotTable].[FAIN].&[DC-75-0002]", "[CSVFolderPivotTable].[FAIN].&[DC-75-0003]", "[CSVFolderPivotTable].[FAIN].&[DC-75-0004]", "", "", "[CSVFolderPivotTable].[FAIN].&[DC-90-X088]")

Can any please help with this.

Thanks in advance.
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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