VBA UBound功能 [英] VBA UBound Function

查看:136
本文介绍了VBA UBound功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的Visual Basic for Applications(VBA)中的代码探索UBound应用程序.假设我有一个4 x 2数组...(A1:B4),我想计算行数.我认为我的代码应该是...

I'm trying to explore UBound applications for my code in Visual Basic for Applications (VBA). Let's say I have a 4 by 2 array...(A1:B4) and I want to count the number of rows. I would think my code would be...

Function test(list) As Double
   test = UBound(list)
End Function

我的输入是=test(A1:B4),但到目前为止,我得到的是"#value!".错误.我以为回报会是4.

My input is =test(A1:B4)but so far I get "#value!" error. I thought the return would be 4.

我做错了什么?我知道如何使用row命令获取行数,但是我只想进行编码练习.

What am I doing wrong? I know how to get the number of rows using the row command but I simply want to go through the coding exercise.

推荐答案

List是范围对象,而不是数组. Range.Value将返回范围内的值数组,而Range.Formula将返回范围内的公式数组.

List is range object not an array. Range.Value will return an array of values from a range and Range.Formula will return an array of formulas from a range.

Function test(list As Range) As Double

    test = UBound(list.Value)

End Function

这篇关于VBA UBound功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆