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?

More than 1 year has passed since last update.

VBAで一次元配列を作成する関数

Last updated at Posted at 2022-10-17

VBAで一次元配列を作成する方法

基本的には、配列を定義するときには以下のように
一つずつ定義する必要がある。

Sub test()

Dim str(2) As Variant

    str(0) = "a"
    str(1) = "b"
    str(2) = "c"

End Sub

この定義の仕方は少し面倒なので、一次元配列の定義を簡単にする関数を作成。

Sub test()

Dim str() As Variant

    str = ArrayDefinition("a", "b", "c")

End Sub

Public Function ArrayDefinition(ParamArray arr()) As Variant
    ArrayDefinition = arr    
End Function

image.png

一行で3つの関数を定義できている。
変数定義が多い時には定義が簡単になる、と思う。

0
0
1

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?