简体   繁体   English

在没有VBA / UDF的情况下追加或添加到数组

[英]Append or prepend to array without VBA/UDF

In Excel, is there a built-in formula/function to append or prepend a value to an array? 在Excel中,是否有内置的公式/函数来为数组附加或前置一个值? So suppose I have my own UDF, MyFunc(...) that returns an array of values. 所以假设我有自己的UDF,MyFunc(...)返回一个值数组。 Can I append or preprend a single value to this result using a reference to a single cell? 我可以使用对单个单元格的引用将单个值附加或预先渲染到此结果吗?

As we discussed in the comments, here is a possible answer: 正如我们在评论中所讨论的,这是一个可能的答案:

AFAIK, no formula can do this and there are no append function in VBA. AFAIK,没有公式可以做到这一点,并且VBA中没有附加功能。 Yet, you could use the ConcatenateArrays function from Chip Pearson 但是,您可以使用Chip PearsonConcatenateArrays函数

This can be achieved using standard Excel array functions. 这可以使用标准Excel数组函数来实现。

For illustration, lets assume MyFunc is 为了说明,我们假设MyFunc是

Function MyFunc(r As Range) As Variant
    MyFunc = r.Value
End Function

Where the passed range is more than one cell, this returns a two-dimensional array. 如果传递的范围是多个单元格,则返回二维数组。

When entered as an array formula like =D1&MyFunc(A2:C7)&E1 this prepends D1 and appends E1 当输入数组公式如=D1&MyFunc(A2:C7)&E1这前缀D1并附加E1

It can also be used in a standard non-array formula, where an array parameter is expected, as shown in cell D12 below 它也可以用于标准的非数组公式,其中需要一个数组参数,如下面的单元格D12所示

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM