从Excel VBA中的一系列单元格创建数组
以下内容与我发现的在线解决方案几乎相同:
Dim iAmount() As Variant
Dim INum As Integer
iAmount = Range("C23:W23")
'The example uses iAmount = Range("A1:A11")
For iNum = 1 to Ubound(iAmount)
Debug.Print iAmount(iNum,1)
Next iNum
End Sub
但是,当我尝试使用此数组时,我会收到错误9,这意味着我引用了不存在的变量。
The following is pretty much identical to the solutions online that I've found:
Dim iAmount() As Variant
Dim INum As Integer
iAmount = Range("C23:W23")
'The example uses iAmount = Range("A1:A11")
For iNum = 1 to Ubound(iAmount)
Debug.Print iAmount(iNum,1)
Next iNum
End Sub
However when I try to work with this array I get error 9 which I interpret to mean that I referenced a variable that doesn't exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在阅读行而不是列,这就是为什么您的代码不起作用的原因。您的范围由1行和21列组成。
您可以读取这样的列:
读取任何完整范围的正确方法就是这样:
You are reading the rows instead of columns which is why your code doesn't work. Your range is composed of 1 row and 21 columns.
You can read the columns like this:
The correct way to read any full range is like this: