如何在VBA为Excel初始化多维数组变量 [英] How to initialize a multidimensional array variable in vba for excel

查看:1067
本文介绍了如何在VBA为Excel初始化多维数组变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助微软网站提出以下建议code应该工作

暗淡数= {{1,2},{3,4},{5,6}}

不过,我得到一个请编译错误,当我尝试一个excel VBA模块中使用它。
下面做工作,为一维数组:

A =阵列(1,2,3,4,5)

但是我没有设法找到做同样用于2D​​阵列的方法。
任何想法?


解决方案

  

微软网站显示...


这对于建议VB.NET但不是VBA。

有关VBA你在正确的方向wehe。你可以这样做:

 黯淡了为Variant
A =阵列(阵列(1,2),阵列(3,4),阵列(5,6))

The Microsoft site suggests the following code should work:

Dim numbers = {{1, 2}, {3, 4}, {5, 6}}

However I get a complile error when I try to use it in an excel VBA module. The following does work for a 1D array:

A = Array(1, 2, 3, 4, 5)

However I have not managed to find a way of doing the same for a 2D array. Any ideas?

解决方案

The Microsoft site suggests...

This suggestion for VB.NET but not VBA.

For VBA you wehe in the right direction. You can do:

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

这篇关于如何在VBA为Excel初始化多维数组变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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