Hello,
I would like to select only one pivotitem each time, but I don't know how to do that. How can i get Pvtltm number? I think the problem is in the part marked in red.
Sub z()
Dim ws As Worksheet, pt As PivotTable, pf As PivotField
Dim BO As Long
Dim PvtItm As PivotItem
Set ws = ActiveSheet
Set pt = ws.PivotTables
Set pf = pt.PivotFields
BO = pf.PivotItems.Count
For i = 1 To BO
For Each PvtItm In pf.PivotItems
If PvtItm = i Then
PvtItm.Visible = True
Else
PvtItm.Visible = False
End If
Next PvtItm
Next i
End Sub
I would like to select only one pivotitem each time, but I don't know how to do that. How can i get Pvtltm number? I think the problem is in the part marked in red.
Sub z()
Dim ws As Worksheet, pt As PivotTable, pf As PivotField
Dim BO As Long
Dim PvtItm As PivotItem
Set ws = ActiveSheet
Set pt = ws.PivotTables
Set pf = pt.PivotFields
BO = pf.PivotItems.Count
For i = 1 To BO
For Each PvtItm In pf.PivotItems
If PvtItm = i Then
PvtItm.Visible = True
Else
PvtItm.Visible = False
End If
Next PvtItm
Next i
End Sub