最近、問題に直面しています。VBAピボットテーブルとコード
マイシート「Sheet1」にピボットテーブル「Dyn40」があります。 PivotFieldの1つが「オプション」であり、可能なPivotItemの1つが「Potato」です。私は438 #ERRORエラーが生じています:オブジェクトはこのプロパティまたはメソッド
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
エラーがどこにあるのかは言わないので、 'ListCount'を持たない' PivotField'と仮定します。 – GSerg
@GSergのコメントの続きとして、 'RecordCount'はそこで動作しますか? –