在Array()中使用“empty”

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,但无论如何,现在我想了解在这个代码中“空”的用法,以增加更多的价值。

我试过了:

 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) 

“Execusiion错误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”在德语中表示“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, Empty) 'To copy value B aProducts(lRow) = Array(.Cells(aPos(1)).Value2, Empty, .Cells(aPos(3)).Value2, Empty) 'To copy value C aProducts(lRow) = Array(.Cells(aPos(1)).Value2, Empty, Empty, .Cells(aPos(4)).Value2) 

我也想你想更新.Cells(aPos(4)).Value2)有一个4而不是一个3