【发布时间】:2015-06-17 07:43:19
【问题描述】:
我目前正在为 Excel 编写宏。首先,我想将我的工作表“Filter”中第 20 行的变量设置读取到我的变量“test”中:
' Define Last Column with a value
LastCol = Sheets("Filter").Cells(20, Sheets("Filter").Columns.Count).End(xlToLeft).Column
Col_Letter = Split(Cells(1, LastCol).Address(True, False), "$")(0)
' Read Data into variable
test = Sheets("Filter").Range("B20:" & Col_Letter & "20").Value
到目前为止,这工作正常,我得到了一个具有类似结构的变体:
test
test(1)
test(1,1) = value1
test(1,2) = value2
test(1,3) = value3
...
我的问题来了: 当我只有一个值要读取时,结构会自动更改为:
test = value1
如何将结构更改为这个?
test
test(1)
test(1,1) = value1
我的问题是,使用这个变量时,我在代码中遇到了各种问题(ubound、lbound、...)。
【问题讨论】:
-
您的其他代码应该在尝试循环之前检查
test是否是一个数组。 -
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
感谢您的意见!我猜 R3uK 有最结构化的答案:)
标签: vba excel variables data-structures