有没有一种方法可以使用单行将值分配给VBA中的Option Base 1阵列?

问题描述:

我正在将整数(总共11个)分配给索引为1到11的数组,一次分配一个索引.

I am assigning integers (11 in total) to an array with index 1 to 11, one index at a time.

有没有一种方法可以像在Matlab中那样在一行中完成它.

Is there a way to do it in one line, similar to how it is done for example in Matlab.

我现在的做法:

Dim cols(1 To 11) As Integer

cols(1) = 2
cols(2) = 3
cols(3) = 5
cols(4) = 6
cols(5) = 7
cols(6) = 9
cols(7) = 10
cols(8) = 13
cols(9) = 14
cols(10) = 15
cols(11) = 16

我想怎么做

Dim cols(1 To 11) As Integer

cols = [2,3,5,6,7,9,10,13,14,15,16]

我知道无需将变量定义为数组即可完成此操作,但是它将返回索引为0到10的数组:

I am aware that it can be done without defining the variable as an array, but that returns the array with index 0 to 10:

Dim cols As Variant

cols = Array(2,3,5,6,7,9,10,13,14,15,16]

如果Variant数组没问题:

If a Variant array is OK:

Dim cols()
cols = [{2,3,5,6,7,9,10,13,14,15,16}]