vba - Array() 中 "empty"的用法

标签 vba excel

aProducts(lRow) = Array("Id Product", "Value A", "Value B")

'To copy value A
aProducts(lRow) = Array(.Cells(aPos(1)).Value2, .Cells(aPos(2)).Value2, Empty)

'To copy value B
aProducts(lRow) = Array(.Cells(aPos(1)).Value2, Empty, .Cells(aPos(3)).Value2)

大家好,

我在循环中使用这段代码来复制一些值及其 ID,但无论如何,现在我想了解这段代码中“Empty”的用法,以便添加更多值。

我尝试过:

aProducts(lRow) = Array("Id Product", "Value A", "Value B", "Value C")

'To copy value A
aProducts(lRow) = Array(.Cells(aPos(1)).Value2, .Cells(aPos(2)).Value2, Empty)

'To copy value B
aProducts(lRow) = Array(.Cells(aPos(1)).Value2, Empty, .Cells(aPos(3)).Value2)

'To copy value C
aProducts(lRow) = Array(.Cells(aPos(1)).Value2, Empty, Empty, .Cells(aPos(4)).Value2)

“执行错误9”

提前致谢,对我的英语水平表示抱歉:/

编辑 1

您可以在此处获取文件:https://drive.google.com/file/d/0B5DpGwPWsIfbWWlJRDAzZldYek0/view?usp=sharing

编辑2

谢谢大家,我刚刚发现我忘了删除

ReDim Preserve aProducts(lRow)

最佳答案

写下以下内容:

Option Explicit

Sub TestMe()

    Dim arr_var     As Variant

    arr_var = Array(Empty, Empty, 5)
    Stop
End Sub

然后运行它。将鼠标放在 arr_var 上单击,按 Shift + F2,您将看到以下内容: “Leer”在德语中是“空”的意思。 enter image description here

关于vba - Array() 中 "empty"的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40633265/

相关文章:

vba - 运行时错误 '3706' : Provider cannot be found -Visual Basic

vba - 在 MS Access 中附加链接表时出现运行时错误

VBA脚本每次都会崩溃

vba - Application.WorksheetFunction.SumProduct wsf.CountIfs 与 4 个数组

c# - 使用 EPplus 向 Excel 添加文本

vba - 在 protected 工作表 Excel 功能区上启用清除过滤器

Excel:如果单元格值增加->播放声音

vba - 计算平均值时单元格和范围之间的差异

python - NoneType 即使定义了属性也会出错?

arrays - 查找字符串是否在二维 VBA Excel 数组中