|
Sub try()
Const Trg = "F1" 'フィールド名
Const Lst = "A,B,C" '表示させるitemリスト
Dim pf As PivotField
Dim r As Range
Dim x As Long
Dim v, s, si
With ActiveSheet.PivotTables(1)
.RefreshTable
On Error Resume Next
Set pf = .PivotFields(Trg)
Set r = Intersect(pf.DataRange, .RowRange)
On Error GoTo 0
If Not r Is Nothing Then
v = r.Item(1).Value
x = r.Count - 1
If x > 1 Then
r.Resize(x).Offset(1).Delete
End If
s = Split(Lst, ",")
For Each si In s
pf.PivotItems(si).Visible = True
Next
If IsError(Application.Match(v, s, 0)) Then
pf.PivotItems(v).Visible = False
End If
End If
End With
Set pf = Nothing
Set r = Nothing
End Sub
..こんな感じです。
|
|