Run-time error '1004': Unable to set the Visible property of the PivotItem class
Excel VBA:
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pf = pt.PivotFields("Snapshot Date")
For Each pi In pf.PivotItems
If pi.Name <> "(blank)" Then
pi = DateValue(pi) 'I have tried using Cdate, Cdbl, Cstr as well.
End If
Next pi
Errors happen here:
i = 1
Do Until i >= pf.PivotItems.count - 1
For Each pi In pf.PivotItems
pi.Visible = False 'Error here
Next pi
pf.PivotItems(i).Visible = True '.. And here!
pf.PivotItems(i + 1).Visible = True
Loop
The pivot items are dates, not sure if I need to format them before I can turn visibility on/off?
I have googled endlessly and could not find any solution to this :( Something about non-contiguous items, but I don't quite understand.
http://www.contextures.com/xlpivot04.html#Option
– Doug Glancy