数组从范围在Excel VBA [英] Array from Range in Excel VBA
问题描述
我试图从一系列单元格中获取一个数组,但是数组显示最多为1个元素宽度。
这里是代码:
Dim item As Variant
MsgBox Range(D19:H19)。计数
item = Range(D19:H19)值
MsgBox LBound(item)& & UBound(item)
根据我的理解项目应该包含一个2D数组...但是我获得以下结果
第一个MsgBox打印5
第二个MsgBox打印1 1
发生什么事?
问题在于LBound和UBound
jtolle对于LBound是正确的和UBound。
LBound(item,2)
UBound(item,2)
但是,项目不能作为数组变暗(你会得到一个错误)。
我认为这是你想要的
Dim item作为变量
MsgBox范围(D19:H19)。计数
item =范围(D19:H19)值
MsgBox LBound(item,2)& & UBound(item,2)
对于i = LBound(item,2)到UBound(item,2)
MsgBox项(1,i)
下一个
Well I've been struggling with the little bit of code and can't seem to get around it ...
I'm trying to get an array from a range of cells, the array however is showing up to be 1 element wide.
Well here's the code:
Dim item As Variant
MsgBox Range("D19:H19").Count
item = Range("D19:H19").Value
MsgBox LBound(item) & " " & UBound(item)
as per my understanding item should contain a 2D array... however I'm getting the following result 1st MsgBox prints 5 2nd MsgBox prints 1 1
What's going wrong?
The problem is in LBound and UBound
jtolle was correct about the LBound and UBound.
LBound(item, 2)
UBound(item, 2)
However, item must not be dimmed as an array (you'll get an error).
I think this is what you want
Dim item As Variant
MsgBox Range("D19:H19").Count
item = Range("D19:H19").Value
MsgBox LBound(item, 2) & " " & UBound(item, 2)
For i = LBound(item, 2) To UBound(item, 2)
MsgBox item(1, i)
Next
这篇关于数组从范围在Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!