LoginSignup
14
16

More than 5 years have passed since last update.

VBAでの配列

Posted at

概要

VBAで配列を扱う場合のメモ

ソース

末尾に追加

Sub main()
    ' Array()は、Variant型になります
    Dim a As Variant
    a = Array(1, 2, 3)
    b = 4

    ' 要素数を拡大します。
    ' Preserveを付けないとデータが消えます。
    '   Redim - 要素数の変更
    '   UBound - 要素数の取得
    ReDim Preserve a(UBound(a) + 1)
    a(UBound(a)) = b
End Sub

簡単なマージ

マージ関数が見つからないので、簡単な結合方法

Sub sample_push()
    ' Array()は、Variant型になります
    Dim a As Variant
    a = Array(1, 2, 3)
    b = Array(4, 5, 6)

    ' splitを利用して、配列を生成します。
    ' 分割文字は、場合に合わせて変更します。
    c = Split(Join(a, "@") & "@" & Join(b, "@"), "@")
End Sub
14
16
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
14
16