在VBA中声明数组
我是VBA Excel应用程序的新手。
我被告知通过使用“ Option equarlicit”语句来声明整个代码中的所有变量。
在下面的代码(这只是实际程序的一小部分)中,我正在尝试读取范围C4:L6的内容,并将其分配给变量“ bar”:
Option Base 1
Option Explicit
Sub My_PROGRAM()
Dim Bar() As Long
Bar = Worksheets("Sheet1").Range("C4:L6").Value 'Reads the contents of the range
End Sub
我不断获得运行时错误' 13' - 类型不匹配。
我的问题是,如何声明2D数组?我尝试了昏暗的栏(1至3、1至10),但这也没有用。
如果我不明确使用选项,则该程序可以正常工作,
Option Base 1
Sub My_PROGRAM()
Bar = Worksheets("Sheet1").Range("C4:L6").Value 'Reads the contents of the range
End Sub
谢谢
I'm new to Excel applications with VBA.
I've been told to declare all the variables throughout my code, by using the "Option Explicit" statement.
In the code below (which is only a small part of the actual program), I'm trying to read the contents of the range C4:L6 and assigns those to the variable "Bar":
Option Base 1
Option Explicit
Sub My_PROGRAM()
Dim Bar() As Long
Bar = Worksheets("Sheet1").Range("C4:L6").Value 'Reads the contents of the range
End Sub
I keep getting a Run-Time error '13' - type mismatch.
My question is, how do I declare a 2D array? I tried Dim Bar(1 to 3, 1 to 10) but that didn't work either.
If I don't use Option explicit, the program works just fine
Option Base 1
Sub My_PROGRAM()
Bar = Worksheets("Sheet1").Range("C4:L6").Value 'Reads the contents of the range
End Sub
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论