Arrays 数组不一致性
我在这里遇到了很多关于数组代码的问题- 如果我运行这个:Arrays 数组不一致性,arrays,excel,vba,Arrays,Excel,Vba,我在这里遇到了很多关于数组代码的问题- 如果我运行这个: Sub ArrayRunner() Dim PipeBArray() As Variant Dim i As Integer PipeBArray = ThisWorkbook.Sheets(1).Range("A1:A6").Value MsgBox Str(UBound(PipeBArray)) & Str(LBound(PipeBArray)) For i = LBound(PipeBArray) To UBoun
Sub ArrayRunner()
Dim PipeBArray() As Variant
Dim i As Integer
PipeBArray = ThisWorkbook.Sheets(1).Range("A1:A6").Value
MsgBox Str(UBound(PipeBArray)) & Str(LBound(PipeBArray))
For i = LBound(PipeBArray) To UBound(PipeBArray)
MsgBox PipeBArray(i)
Next i
MsgBox "Done!"
End Sub
然后我得到错误9-for循环中的行上的下标超出范围-当我观察变量“I”时,它告诉我I的值是1。。。这发生在for循环的第一个实例上
有人能帮我看看我做错了什么吗
谢谢大家
Joe当您将范围设置为这样的数组时,VBA会自动将其设置为二维数组。所以你需要像这样引用它:
MsgBox PipeBArray(i, 1)
而不是:
MsgBox PipeBArray(i)
我建议您提供更多信息。还想补充一下
Dim Temp As Variant
Dim Dict As New Dictionary
' fill dictionary here
Temp = Dict.Items
创建一维数组。
我只是遇到了与上述问题相反的情况
问候,,
乔谢谢斯托宾-感觉有点傻,因为它太简单了!哈哈哈。别难过,我想一路上大多数人都会被它绊倒。