填充多维数组 [英] Fill multidimensional array

查看:130
本文介绍了填充多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Excel VBA中填充多维数组。可以填充一个1d数组,如下所示:

I was wondering how to fill a multi-dimensional array in Excel VBA. A 1d array can be filled as follows:

Dim myarray as variant

myarray = Array("sheep", "goat", "chicken")

维度数组?

推荐答案

您可以这样做:

Dim a
a = [{1,2;3,4;5,6}]

限制:


  • 只适用于类型的数组,因为 [x] Evaluate(x)的缩写,这意味着 x 通过Excel解释,Excel只返回变体。所以声明 Dim a As Variant 或数组 Dim a()As Variant 工作正常。但不包括任何其他类型的阵列 Dim a()As String failed。

  • This only works with arrays of type Variant, because [x] is shorthand for Evaluate("x") which means that x is interpreted via Excel, and Excel only returns Variants. So declaring Dim a As Variant or an array Dim a() As Variant works fine. But not any other type of array e.g. Dim a() As String fails.

这仅适用于一种特定类型的多维数组,即两个维数组。不是三维,四维等。

This only works for one specific kind of multi-dimensional array, namely two-dimensional arrays. Not three-, four- etc. dimensional.

这篇关于填充多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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