I have been facing a problem lately and any help to solve is much appreciated.
My sheet “Sheet1” has a PivotTable “Dyn40”. One of the PivotFields is “Options” and one of the possible PivotItems is “Potato”. I am having error #error 438: object doesn't support this property or method
Sub FindPriority()
Dim pass As String
pass = "user"
With Worksheets("Sheet1")
.Activate
.Unprotect Password:=pass
Range("TK2").Select ‘ < --- is this necessary ?
ActiveSheet.PivotTables("Dyn40").PivotCache.Refresh
If ActiveSheet.PivotTables("Dyn40").PivotFields("Options").ListCount = 1 Then ‘check if there is at least one item in the field
If ActiveSheet.PivotTables("Dyn40").PivotFields("Options").PivotItems("Potato").count = 1 Then ‘check if there is at least one single item named “Potato”
CreateObject("WScript.Shell").Popup "Only one item exists and its name is Potato" ‘ if there exists, then message pops up
End If
Else
If ActiveSheet.PivotTables("Dyn40").PivotFields("Options").ListCount > 1 Then ‘check if there is more than one item in the field
If ActiveSheet.PivotTables("Dyn40").PivotFields("Options").PivotItems("Potato").count = 1 Then ‘check if there is at least one single item named “Potato”
CreateObject("WScript.Shell").Popup "There is more than one item and one of them is Potato"‘ if there exists, then message pops up
ActiveSheet.PivotTables("Dyn40").PivotFields("Options").PivotItems("Potato").Visible = False ‘ and then the name “Potato” is hidden
End If
Else
CreateObject("WScript.Shell").Popup "There is nothing in here" 'if there are no fields available, message pops up
End If
End If
End With
End Sub
The next question is … if I want to replace Potato by “ “ (empty field) how will this snippet look like?