I have the following code that attempts to loop through the selections on a pivot table field and returns a string with the selected items. It works as long as only 1 item is selected but if the multiple item flag is set and two or more selections are made, all the items return visible = false. Is there another property or do I need to do something with the page orientation?
Here is the code:
Function PTfilters(fldName As String) As String
Dim PT As Excel.PivotTable
Set PT = ThisWorkbook.Sheets("MySheet").PivotTables("myPivotTable")
Dim piFilter As PivotItem
Dim iFilterCount As Integer
iFilterCount = 0
For Each piFilter In PT.PivotFields(fldName).PivotItems
If piFilter.Visible Then
iFilterCount = iFilterCount + 1
PTfilters = PTfilters & "," & piFilter.Name
End If
Next piFilter
PTfilters = Mid$(PTfilters, 2)
End Function