Excel 数组公式有编程接口吗?
例如,假设我
{={1,2,3,4,5}}
在一个牢房里。有什么方法可以找出该数组中有多少个元素以及这些元素是什么?
现在实现 @chris neilsen 的想法,我现在有了一个如下所示的 VBA 函数
Function rinfo(r As Range) As String
With r.CurrentArray
rinfo = .Address & ", " & .Rows.Count & ", " & .Columns.Count & ", " & .Value & ", " & .Value2
End With
End Function
,但是其中的数据看起来并不乐观,即
$A$29, 1, 1, 1, 1
Rows.Count 和 Columns.Count 如果它们正在计算中使用的行和列,那么它们是有意义的工作表。但作为数组公式中数据的指示,没有。
For example, suppose I have
{={1,2,3,4,5}}
in a cell. Is there any way to find out how many elements are in that array, and what those elements are?
Now implementing @chris neilsen's idea, I've now got a VBA function as below
Function rinfo(r As Range) As String
With r.CurrentArray
rinfo = .Address & ", " & .Rows.Count & ", " & .Columns.Count & ", " & .Value & ", " & .Value2
End With
End Function
however the data from it doesn't look to hopeful, viz
$A$29, 1, 1, 1, 1
The Rows.Count and Columns.Count make sense if they are counting the rows and cols used in the worksheet. But as an indication of the data in the array formula, no.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的公式仅占用一个单元格,并且单元格只能包含标量值,因此计算单元格后它将包含 1。
但是您可以从 VBA 计算公式,这可以给您一个数组结果。如果您的公式在 A1 中,
则将导致 vArr 包含 4 个数字的 4 个变体的数组。
Evaluate 方法有几个“怪癖”:请参阅 我的网页之一了解详细信息。
Your formula only occupies a single cell, and a cell can only contain a scalar value, so after the cell has been calculated it will contain 1.
But you can evaluate the formula from VBA and that can give you an array result. If your formula is in A1 then
will result in vArr containing an array of of 4 variants of the 4 numbers.
There are several "quirks" to the Evaluate method: see one of my web pages for details.
在
Sub
中,如果cl
是Range
并且设置为属于数组公式一部分的单元格,则返回包含以下内容的范围:数组公式。
如果您的示例公式位于单元格
A1:E1
中,并且活动单元格是单元格 A1 .. E1 中的任何一个,则运行将返回一条消息
ref = $A$1:$E$1
您可以使用
.Rows.Count
和.Columns.Count
获取大小,使用.Value
获取值In a
Sub
, ifcl
is aRange
and is set to a cell that is part of an array formula, thenreturns the range that contains the array formula.
If your example formula was in cells
A1:E1
and the activecell is any of cells A1 .. E1, then runningwould return a message of
ref = $A$1:$E$1
You can use
.Rows.Count
and.Columns.Count
to get the size, and.Value
to get the values