VBA里应该怎么定义一个动态的二维数组?
我是这么声明的PublicarrAsVariant在一个过程里赋值Subtest()arr={"饮料","2101","2501";"食品","2102","2601";...
我是这么声明的
Public arr As Variant
在一个过程里赋值
Sub test()
arr = {"饮料","2101","2501"; "食品","2102","2601" ; "蔬菜","2103","2701"}
End Sub
然后,就 直报错,哪里不对吗?
我想让这个二维数组成这个样子(三行两列):
"饮料" "2101","2501"
"食品" "2102","2601"
"蔬菜" "2103","2701"
应该怎么声明和赋值啊?
字符串里的引号也要保留. 展开
Public arr As Variant
在一个过程里赋值
Sub test()
arr = {"饮料","2101","2501"; "食品","2102","2601" ; "蔬菜","2103","2701"}
End Sub
然后,就 直报错,哪里不对吗?
我想让这个二维数组成这个样子(三行两列):
"饮料" "2101","2501"
"食品" "2102","2601"
"蔬菜" "2103","2701"
应该怎么声明和赋值啊?
字符串里的引号也要保留. 展开
4个回答
推荐于2018-05-09 · 知道合伙人互联网行家
关注
展开全部
VBA中动态定义一个二维数组,案例代码如下:
//定义动态数组tt
Sub tt()
Dim a() As Integer
ReDim a(1 To 2, 1 To 1) As Integer
a(1, 1) = 10
i = 10
ReDim Preserve a(1 To 2, 1 To i) As Integer
MsgBox a(1, 1)
End Sub
展开全部
你对ubound函数的理解没错。问题在于数组a的结构只是你自己主观想象。
你在vba编辑器中,选择视图→本地窗口,然后按f8逐行测试代码,自然可以在本地窗口中看到数组a的结构。这样不就一目了然了,知道问题在哪儿了吗。
你在vba编辑器中,选择视图→本地窗口,然后按f8逐行测试代码,自然可以在本地窗口中看到数组a的结构。这样不就一目了然了,知道问题在哪儿了吗。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试一试: 把 {"饮料","2101 。。。} 用 [ ] 围起来。
arr = [ {"饮料","2101","2501"; "食品","2102","2601" ; "蔬菜","2103","2701"} ]
arr = [ {"饮料","2101","2501"; "食品","2102","2601" ; "蔬菜","2103","2701"} ]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |