2016-10-05 10 views
2

MultipleItemsが許可されている場合、どの項目がピボットテーブルフィルタでチェックされているかを知ることはできますか?ピボットテーブルで複数のアイテムが選択されているかどうかを確認する方法は?

私はそれを確認するには.Visibleプロパティを参照してくださいが、複数の項目が許可されていない場合にのみ機能します。 複数の項目が許可され、.Visibleプロパティがチェックされている場合は、選択したすべての項目の代わりに「すべて」が表示されます。

これを行う方法は?

Dim pvt As PivotTable 
Dim fld As PivotField 
Dim itm As PivotItem 
Dim flt As PivotFilter 

Dim i As Integer 


Set xbFuente = ThisWorkbook 
Set xlDatos = xbFuente.Worksheets("TABLAS") 
Set pvt = xlDatos.PivotTables("MAIN") 

pvt.ManualUpdate = True 
Application.EnableEvents = False 
Application.ScreenUpdating = False 

If pvt.ShowPageMultipleItemLabel = True Then 
    Debug.Print "The words 'Multiple Items' can be displayed." 
End If 

For Each fld In pvt.PageFields   
    Debug.Print fld.Name & " -- " & fld.Orientation & " -- " & fld.EnableItemSelection & " -- " & fld.EnableMultiplePageItems & " -- " 


    If fld.AllItemsVisible = True Then 
    ' If all items are visible "ALL" 
     For Each itm In fld.VisibleItems 
      Debug.Print "---- ALLITEMSVISIBLE TRUE --" & "VISIBLE" & " -- " & itm.Name & " -- " & itm.Visible 
     Next 
    Else 
     For Each itm In fld.VisibleItems 
      Debug.Print "---- ALLITEMSVISIBLE FALSE --" & "VISIBLE" & itm.Name & " -- " & itm.Visible 
     Next 
     For Each itm In fld.HiddenItems 
      Debug.Print "--------ALLITEMSVISIBLE FALSE --" & "HIDDEN -- " & itm.Name & " -- " & itm.Visible 
     Next 
     For Each itm In fld.PivotItems 
      Debug.Print "--------ALLITEMSVISIBLE FALSE --" & "HIDDEN -- " & itm.Name & " -- " & itm.Value 
     Next 
    End If 

    Next 

結果Warranty Flag -- 3 -- Verdadero -- Verdadero -- ---- ALLITEMSVISIBLE FALSE --VISIBLE(All) -- Verdadero --------ALLITEMSVISIBLE FALSE --HIDDEN -- A -- Falso --------ALLITEMSVISIBLE FALSE --HIDDEN -- I -- Falso --------ALLITEMSVISIBLE FALSE --HIDDEN -- O -- Falso --------ALLITEMSVISIBLE FALSE --HIDDEN -- P -- Falso

答えて

1

以下のサンプルコードを試してみてください。

Sub Check_PivotFilter_Selection() 

Dim pvt As PivotTable 
Dim fld As PivotField 
Dim itm As PivotItem 
Dim flt As PivotFilter 

Dim i As Integer 

Set xbFuente = ThisWorkbook 
Set xlDatos = xbFuente.Worksheets("TABLAS") 
Set pvt = xlDatos.PivotTables("MAIN") 

pvt.ManualUpdate = True 
Application.EnableEvents = False 
Application.ScreenUpdating = False 

If pvt.ShowPageMultipleItemLabel = True Then 
    Debug.Print "The words 'Multiple Items' can be displayed." 
End If 


For Each fld In pvt.PageFields 
    Debug.Print fld.Name & " -- " & fld.Orientation & " -- " & fld.EnableItemSelection & " -- " & fld.EnableMultiplePageItems & " -- " 

    ' loop through all items in Field, and check which ones are Selected (and which ones are not) 
    For Each itm In fld.PivotItems 

     If itm.Visible = True Then 
      Debug.Print " Item " & itm.Name & " in Field " & fld.Name & " is Visible (Selected) " 
     Else 
      Debug.Print " Item " & itm.Name & " in Field " & fld.Name & " is Hidden (Not Selected) " 
     End If 

    Next itm  
Next fld 

End Sub 
0

を私はあなたのコードをチェックして、私は私と同じ結果を持っています。先週のテストでは、.hidden &の.visibleプロパティで試してみました。 "複数の項目を選択"を選択しなかった場合は正常に動作します。

Warranty Flag -- 3 -- Verdadero -- Verdadero -- 
Item I in Field Warranty Flag is Hidden (Not Selected) 
Item O in Field Warranty Flag is Hidden (Not Selected) 
Item IW in Field Warranty Flag is Hidden (Not Selected) 

ピボットテーブルをVBAで作成されていない、手動で作成されたと私は、Excel 2010

で働いています
関連する問題