Hi Guys,
Can anyone help me streamline this code further?
The code looks at report filter in Pivot and makes a list of items included and excluded.
Biz
Can anyone help me streamline this code further?
The code looks at report filter in Pivot and makes a list of items included and excluded.
Code:
Sub Information()
'Including
Dim aItem As PivotItem
With Range("C1")
.Value = "Including"
.Font.Bold = True
.Offset(1, 0).ClearContents
End With
For Each aItem In ActiveSheet.PivotTables("PivotTable1").PivotFields("Spirits").PivotItems
If aItem.Visible = True Then
Range("C2") = Range("C2") & aItem & ","
End If
Next
If Range("C2").Value <> "" Then
Range("C2") = Left(Range("C2"), Len(Range("C2")) - 1) ' Remove unnecessary commas
End If
'Excluding
With Range("D1")
.Value = "Excluding"
.Font.Bold = True
.Offset(1, 0).ClearContents
End With
For Each aItem In ActiveSheet.PivotTables("PivotTable1").PivotFields("Spirits").PivotItems
If aItem.Visible = False Then
Range("D2") = Range("D2") & aItem & ","
End If
Next
If Range("D2").Value <> "" Then
Range("D2") = Left(Range("D2"), Len(Range("D2")) - 1) ' Remove unnecessary commas
End If
End Sub
Biz