A1セルには 部署
B1セルには 日付が入っていて、
A1とB1に指定したセルの値で ピボットテーブル2 のフィルタを更新させたいです。
下記のようなコードで、A1セルの値でフィルタ更新はできるようになったのですが、
B1セルの値のフィルタがうまく設定できません。
複数の場合どのようにしたら良いでしょうか。
Sub test()
Dim pf As PivotField
Dim pf2 As PivotField
Dim r As Range
Dim n As Long
Dim x As String
Dim s, si
Application.ScreenUpdating = False
Set pf = ActiveSheet.PivotTables("ピボットテーブル2").PivotFields("部署")
pf.Orientation = xlRowField
pf.Position = 1
Set r = pf.DataRange
x = r.Item(1).Value
n = r.Cells.Count - 1
If n > 0 Then
r.Resize(n).Offset(1).Delete
End If
s = Split(Lst, ",")
With Worksheets("比較")
s = Application.Transpose(.Range("A1", .Cells(Rows.Count, 1).End(xlUp)).Value)
End With
On Error Resume Next
For Each si In s
pf.PivotItems(si).Visible = True
Next
On Error GoTo 0
If IsError(Application.Match(x, s, 0)) Then
pf.PivotItems(x).Visible = False
End If
pf.Orientation = xlPageField
Application.ScreenUpdating = True
End Sub
ご教授いただければ幸いです。
宜しくお願い致します。