Remove メソッド

Dictionary オブジェクトからキーと項目のペアを削除します。

構文

オブジェクト削除 (キー)

Remove メソッドの構文には、次の指定項目があります。

パーツ 説明
object 必須です。 常に Dictionary オブジェクトの名前です。
key 必須です。 Dictionary オブジェクトから削除するキー/項目ペアに関連付けられているキー

注釈

指定したキーと項目のペアが存在しない場合、エラーが発生します。

次のコードは 、Remove メソッドの使用方法を示しています。

Public Sub Start()

    Dim d As Object
    Set d = CreateObject("Scripting.Dictionary")
    
    d.Add "a", "Athens"
    d.Add "b", "Belgrade"
    d.Add "c", "Cairo"
    
    Debug.Print "Keys, before using Remove."
    PrintKeys d
    
    d.Remove "b"
    
    Debug.Print "Keys, after removing key 'b'."
    PrintKeys d

End Sub

Private Sub PrintKeys(ByVal d As Object)
    
    Dim k As Variant
    For Each k In d.Keys
        Debug.Print k
    Next k
    
End Sub

' The example displays the following output:
' Keys, before using Remove.
' a
' b
' c
' Keys, after removing key 'b'.
' a
' c

関連項目

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。