如何在多个行上拆分一个恒定的2D数组初始化? [英] How to split a constant 2D array initialization on several lines?

查看:43
本文介绍了如何在多个行上拆分一个恒定的2D数组初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个2D数组,该数组不打算更新,只能读取.阅读这个问题,我发现使用评估是这种可能性:

I need to create a 2D array which is not intended to be updated, only read. Reading this question, I found this possibility using evaluate:

Dim varData As Variant
varData = [{1, 2, 3; 4, 5, 6; 7, 8, 9}]

就我而言,值的数量需要将赋值分成几行,例如

In my case, the number of values requires to split the assignment on several lines, e.g.

varData = [{value1, value2; _
            ...; _
            valueM, valueN}]

但是,当使用_拆分此分配时,VBA在第一行抱怨:

However when using _ to split this assignment, VBA complains at the first line with:

编译错误:
缺少尾部支架

Compile Error:
Missing end bracket

我试图找到解释,但是所有示例似乎仅使用一行.怎么了?

I've tried to find the explanation, but all examples seems to use only a single line. What is wrong?

注意:我正在尝试填充数组,而不是填充工作表中的单元格.

Note: I'm trying to populate an array, not cells in a sheet.

推荐答案

我在想这个.

Dim A as Variant
A = Array(Array(1, 2), _
          Array(3, 4), _
          Array(5, 6))

这篇关于如何在多个行上拆分一个恒定的2D数组初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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