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”在德语中是“空”的意思。
关于vba - Array() 中 "empty"的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40633265/