У меня возникла проблема в последнее время, и любая помощь в решении очень ценится.VBA Сводные таблицы и кодировка
Мой лист «Sheet1» имеет сводную таблицу «Dyn40». Одним из PivotFields является «Параметры», и одним из возможных PivotItems является «Картофель». Я имею ошибку #error 438: объект не поддерживает это свойство или метод
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
Следующий вопрос ... если я хочу заменить картошку на ««(пустое поле) как это будет выглядеть фрагмент кода?
В качестве примечания стороны замените странный 'CreateObject (« WScript.Shell »). Popup' с' MsgBox'. Ответ на «<--- это необходимо?» - [нет] (http://stackoverflow.com/q/10714251/11683). – GSerg
Вы не говорите, где ошибка, поэтому я предполагаю, что это «PivotField», у которого нет «ListCount». – GSerg
Как продолжение комментария @ GSerg, работает ли «RecordCount»? –