简体   繁体   English

将INDEX MATCH公式更改为EXCEL中的数组公式

[英]Change INDEX MATCH formula to an array formula in EXCEL

I am trying to create an INDEX MATCH formula that searches through a column containing a list of jpegs and returns all jpegs that start with a particular string and converts them to a hyperlink. 我正在尝试创建一个INDEX MATCH公式,该公式搜索包含jpegs列表的列,并返回以特定字符串开头的所有jpegs ,并将它们转换为超链接。

Currently my formula returns just the first instance, but I'd like it to return all matches. 目前,我的公式仅返回第一个实例,但我希望它返回所有匹配项。

The list of jpegs is in column F (F1:F1000) on Sheet 2 of the workbook. jpeg的列表在工作簿的工作Sheet 2column F (F1:F1000) The string that is being used in the search is the product SKU in column A, sheet 1 . 搜索中使用的字符串是column A, sheet 1的产品SKU。

Here is the working non-array version which I have entered in C2 on sheet 1 and filled down: 这是我在sheet 1 C2输入并填写的工作非数组版本:

=IFERROR(
    HYPERLINK(
         CONCATENATE(sku_url,INDEX(Sheet2!$F$1:$F$1000,
             MATCH(A2&"*",Sheet2!$F$1:$F$1000,0),1))),
    "image not found")

This works for column C , but how can I fill this formula to the right so that column D contains the second image for each sku, E contains the third, and so forth. 这适用于column C ,但是如何在右边填充此公式,以使column D包含每个sku的第二个图像, E包含第三幅图像,依此类推。 I plan to have no more than six images for each SKU, so I have assigned columns C through H to product image URLs. 我计划每个SKU的图像不超过六个,因此我已将columns CH columns C分配给产品图像URL。 If a SKU doesn't have six images, these extra columns should be empty. 如果SKU没有六个图片,则这些多余的列应为空。

Assuming use of Excel 2010 or later: 假设使用Excel 2010或更高版本:

=IF(COLUMNS($A:A)>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),"",IFERROR(HYPERLINK(CONCATENATE(sku_url,INDEX(Sheet2!$F:$F,AGGREGATE(15,6,ROW(Sheet2!$F$1:$F$1000)/(LEFT(Sheet2!$F$1:$F$1000,LEN($A2))=$A2),COLUMNS($A:A))))),"imagenotfound"))

As way of an explanation, the initial IF clause, ie: 作为解释,初始的IF子句即:

IF(COLUMNS($A:A)>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""

is straightforward enough: 很简单:

COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*")

simply gives a count of the total number of rows which match that condition, and since: 简单地给出符合该条件的总行数,并且因为:

COLUMNS($A:A)

which is equal to 1 and becomes, when copied to the right, successively: 等于1,并在向右复制时依次变为:

COLUMNS($A:B)

(which is equal to 2) (等于2)

COLUMNS($A:C)

(which is equal to 3) (等于3)

etc., etc., this clause will be equivalent to, in successive columns: 等,此子句在连续的列中等同于:

IF(1>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""

IF(2>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""

IF(3>COUNTIF(Sheet2!$F$1:$F$1000,$A2&"*"),""

etc., etc., and so a blank will be returned in cells where that initial clause is TRUE . 等,因此在初始子句为TRUE单元格中将返回空白。

The only other clause of note is that which generates an array of successive row numbers for when this condition is met. 注意的唯一其他子句是在满足此条件时生成连续行号的数组。 Unfortunately the COUNTIF statement above is, for technical reasons, not employable within our AGGREGATE construction. 不幸的是,出于技术原因,上面的COUNTIF语句不能在我们的AGGREGATE结构中使用。

Fortunately we can reproduce the results of that COUNTIF statement using another set-up with LEFT . 幸运的是,我们可以使用另一个带有LEFT设置来重现该COUNTIF语句的结果。

Reducing the range in question temporarily from F1:F1000 to F1:F10 to aid the explanation, this part: 为了帮助说明,暂时将相关范围从F1:F1000减小到F1:F10,这部分内容:

LEFT(Sheet2!$F$1:$F$10,LEN($A2))=$A2

will simply generate an array of Boolean TRUE / FALSE returns as to the result of that statement for each of the entries in F1:F10. 只会为F1:F10中的每个条目生成该语句结果的布尔TRUE / FALSE返回数组。 We might have, for example: 例如,我们可能有:

{FALSE;TRUE;FALSE;TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE}

When we then reciprocate the equivalent row numbers for each of those entries with this array of Booleans, ie perform: 然后,当我们使用此布尔数组对每个条目的等效行号进行往复时,即执行:

ROW(Sheet2!$F$1:$F$10)/(LEFT(Sheet2!$F$1:$F$10,LEN($A2))=$A2)

we have: 我们有:

{1;2;3;4;5;6;7;8;9;10}/{FALSE;TRUE;FALSE;TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE}

and since, when coerced by any suitable mathematical operation (of which division is one), Boolean TRUE / FALSE values are coerced into their numerical equivalents ( TRUE =1, FALSE =0), the above becomes: 并且由于在通过任何适当的数学运算(除以1的结果)进行强制运算后,布尔值TRUE / FALSE值被强制转换为其数值等效项( TRUE = 1, FALSE = 0),因此上述内容变为:

{#DIV/0!;2;#DIV/0!;4;5;#DIV/0!;7;#DIV/0!;9;#DIV/0!}

Since AGGREGATE , with a first parameter of 15 is instructed to find the smallest value within an array, and with a second parameter of 6 is instructed to ignore any error values within that array, all that is left is to set the fourth parameter within that function, k , which determines whether the first smallest, second smallest, etc. value should be returned. 由于第一个参数为15的AGGREGATE被指示在数组中找到最小值,第二个参数为6的AGGREGATE被指示忽略该数组中的任何错误值,因此剩下的就是在该数组中设置第四个参数。函数k ,确定是否应返回第一个最小值,第二个最小值等。

Again, by using: 同样,通过使用:

COLUMNS($A:A)

for this parameter, which we know will generate a series of consecutive integers (1, 2, 3, etc.) as copied to the right, we thus guarantee that we will return the required row number to each version of the formula. 对于该参数,我们知道它将生成一系列连续的整数(1、2、3等),如右图所示,因此我们保证将所需的行号返回给公式的每个版本。

Regards 问候

Use the AGGREGATE¹ function with the SMALL sub-function ( 15 ). AGGREGATE¹功能SMALL功能一起使用( 15 )。 Adjust the k parameter to increase with COLUMN as you fill right. 右填充时,调整k参数以COLUMN增大。

The standard (non-array) formula in B2 is, B2中的标准(非数组)公式为

=IFERROR(
    HYPERLINK(
        CONCATENATE(sku_url, INDEX(Sheet2!$F:$F,
            AGGREGATE(15, 6, ROW($1:$999)/(LEFT(Sheet2!$F$1:$F$999, LEN($A2))=$A2), COLUMN(A:A))))),
    "image not found")

Fill right as necessary. 根据需要正确填写。

aggregate_first_Second


¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions. ¹AGGREGATE函数是Excel 2010引入的。在早期版本中不可用。

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

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