0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excel VBAでディクショナリ(連想配列)を使用したい

Posted at

1. はじめに

  • Excel VBAでディクショナリ(連想配列)の使い方を知りたい

2. 開発環境

  • VBA
  • Excel 2021

3. 事前準備

ツール > 参照設定からMicrosoft Scripting Runtimeにチェックする
image.png

4. サンプルコード

  • ディクショナリを宣言して値を取得する
Sample1()
Public Sub Sample1()

    Dim count As Integer
    
    ' ディクショナリを宣言
    Dim dic As New Scripting.Dictionary
    
    ' ディクショナリに値をセット
    With dic
        .Add Key:="JP", Item:="日本語"
        .Add Key:="EN", Item:="英語"
        .Add Key:="KO", Item:="韓国語"
    End With

    ' デバッグ1 全件取得
    For count = 0 To dic.count - 1
        Debug.Print dic.Keys(count) & " " & dic.Items(count)
    Next

    ' デバッグ2 KEYを指定
    Debug.Print dic.Item("JP")

End Sub
実行結果
JP 日本語
EN 英語
KO 韓国語
日本語

4. 参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?