【VBA】Dictionaryの存在確認|DicExists
記事更新日:2022-12-03

Dictionaryの存在確認
Dictionaryに要素が存在していればTrueを返す
Option Private Module
Option Explicit
Public Function DicExists( _
ByVal dic As Object, _
ByVal key As String) As Boolean
DicExists = False
If dic.exists(key) Then DicExists = True
End Function
呼び出し方
Private Sub Test()
Dim i As Long
Dim dic As Object: Set dic = SetDIC
For i = 1 To 100
If Not DicExists(dic, xx) Then 'キー(xx)がdicに存在しなければ
Set dic = AddDicKeyValue(dic, xx, yy) 'キー(xx)と要素(yy)を追加する
'なにかの処理
End If
Next i
End Sub
関連記事
2022-12-03
編集後記:
この記事の内容がベストではないかもしれません。
記事一覧
-
指定の文字より前/後ろをカット 【VBA】文字列から、指定の文字をカットする|指定文字より前/後ろを残す -
ユーザーフォームを半透明にする 【VBA】ユーザーフォームを半透明にしてシートの内容が見えるようにする|waiting-form -
グラフ設定を変更する 【VBA】グラフ設定を動的に変更する -
数値に+ 記号を追加 【VBA】正の数値に+記号を追加|Sgn -
dictionaryをセットする 【VBA】Dictionaryのセット|CreateObject(“Scripting.Dictionary”) -
ブックを閉じる3つ 【VBA】ブックを閉じる3つの方法|保存して/保存しないで/ブック名で/