Forum

Select a string fro...
 
Notifications
Clear all

Select a string from a filter on a pivot table

2 Posts
2 Users
0 Reactions
122 Views
(@meerlenamika)
Posts: 1
New Member
Topic starter
 

Hello everyone

I`m new here and I have no knowledge regarding VBA (none what so ever) so I apologize in advance

I`ve recorded a macro that looks like this:

Sub Team()

'

' Team Macro

'

'

    ActiveSheet.PivotTables("PivotTable1").PivotFields( _

        "[Feature Area].[Team].[Team]").VisibleItemsList = Array( _

        "[Feature Area].[Team].&[T_FW_Superman]&[P_A]", _

        "[Feature Area].[Team].&[T_FW_ Superman]&[P_B]", _

        "[Feature Area].[Team].&[T_FW_ Superman]&[P_C]", _

        "[Feature Area].[Team].&[T_FW_ Superman]&[P_LOS]", _

        "[Feature Area].[Team].&[T_FW_ Superman]&[P_RIO]", _

        "[Feature Area].[Team].&[T_FW_ Superman]&[P_LONDON]", _

        )

End Sub

 

I need to select a string that begins with a specific name:T_FW_ Superman while the ending can be anything (the selection is made from a filter of a pivot table)

I have a lot of these specific names and I need to clear the filter each time before I make another selection

Also, I need to put these names in a combo box for the user to select from

Can someone please help me?

 

Thank you in advance!

 
Posted : 07/05/2018 2:00 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Lena,

Declare a variable:

Dim Fld as PivotField, Itm as PivotItem

Set Fld=ThisWorkbook.Worksheets("Sheet1").PivotTables("PivotTable1").PivotFields("[Feature Area].[Team].[Team]")

     For Each Itm in Fld.PivotItems

           If Itm.Caption Like "*T_FW_Superman*" then

               'do what you need to do...  

                Combobox1.Add Itm.Caption ' this line must be used in a form module, not a regular code module

                Msgbox Itm.Caption

           End If

    Next

Change sheet name to the name of the sheet where this pivot is located.

 
Posted : 09/05/2018 7:29 am
Share: