VBA I Can't Work Exists Method with Dictionary

pivot table

Dim memberDic As Object: Set memberDic = CreateObject("Scripting.Dictionary")
Set memberDic("Team A") = CreateObject("Scripting.Dictionary")

memberDic("Team A")("Tanaka") = 1
memberDic("Team A")("Watanabe") = 2
memberDic("Team A")("Shimizu") = 3

For Each person In ActiveSheet.PivotTables(fy).PivotFields("name").PivotItems
    If Not memberDic("Team A").Exists(person.Name) Then
        'hidden person except Team A
    End If
Next person

I would like to exclude an element using the Exists method. Could you give me some advice?

+4
source share
1 answer

Formalization of the comment published for the question:

Trim the value from the pivot table so that Exists work correctly:

For Each person In ActiveSheet.PivotTables(fy).PivotFields("name").PivotItems
    If Not memberDic("Team A").Exists(Trim(person.Name)) Then
        'hidden person except Team A
    End If
Next person
0
source

Source: https://habr.com/ru/post/1666970/


All Articles