如何在 VBA (excel) 中获取二维数组的长度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40795649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:36:11 来源:igfitidea点击:
How can I get the length of a two dimensional array in VBA (excel)?
提问by Tal Kohavy
How can I get the length of a two-dimensional array in VBA (excel)?
如何在 VBA (excel) 中获取二维数组的长度?
Dim givenData(5, 7) As Double
Dim givenData(5, 7) As Double
I need a command that would return 5, And a command that would return 7.
我需要一个返回 5 的命令,以及一个返回 7 的命令。
回答by A.S.H
Sub ShowArrayBounds()
Dim givenData(3 To 5, 5 To 7) As Double
MsgBox LBound(givenData, 1)
MsgBox UBound(givenData, 1)
MsgBox LBound(givenData, 2)
MsgBox UBound(givenData, 2)
End Sub
You can use UBound-LBound + 1
to get the "size" for each dimension
您可以使用UBound-LBound + 1
获取每个维度的“大小”