有没有一种方法可以使用单行将值分配给VBA中的Option Base 1阵列? [英] Is there a way to assign values to an Option Base 1 array in VBA using a single line?

查看:89
本文介绍了有没有一种方法可以使用单行将值分配给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}]

这篇关于有没有一种方法可以使用单行将值分配给VBA中的Option Base 1阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆