How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?

huangapple go评论77阅读模式
英文:

How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?

问题

我正在尝试编写一个Excel公式,可以在单个单元格中输出与目标参考匹配的表格中的所有项目。例如,我制作了一个包含两列的表格,如下所示:

项目            编号

A1              01
A2              01
A3              02
A4              03
A4              04
A5              04
A6              01
A7              05
A8              06
A9              02
A10             07

可以同时为不同项目分配编号,也可以为一个项目分配多个编号。

在这个表格中,我希望检索与我设置的输入编号相关的所有项目。
例如,输入01会给我返回A1、A2和A6。

输入也可以是多个用逗号分隔的编号,输入设置为"02,05"会返回与这两个编号相关的所有项目:"A3, A7, A9"。

我在Google Sheets中使用了以下公式实现了这一点:

=JOIN(",", UNIQUE(FILTER(A:A, ARRAYFORMULA(REGEXMATCH(","&B:B&",", ",("&SUBSTITUTE(C2, ",", "|")&"),")))))

其中:

  • 列A对应于项目列表
  • 列B对应于组件列表
  • 单元格C2是我写入输入的地方

这个公式完美地运行,但是我需要在Excel中实现相同的功能,我无法在没有Google Sheets中相同功能的情况下“转换”这个公式。

我在网上找到了一些方法,可以输出给定组件的所有匹配项目,但它们没有实现通过逗号分隔的多个输入的可能性。

是否有人知道我该如何做呢?提前谢谢您。

英文:

I am trying to write an excel formula that can output in a single cell all items from a table that matches the target reference. As an example, I have made a table with two columns that looks like the following :

ITEM	           NUMBER

A1                 01
A2                 01
A3                 02
A4                 03
A4                 04
A5                 04
A6                 01
A7                 05
A8                 06
A9                 02
A10                07

Numbers can be attributed to different items simultaneously and items can have more than one number attributed to them.

In this table , I aim to retrieve all items that are related to a number I set as an input.
For example, 01 as an input would give me A1,A2,A6.

This input can also be multiple numbers separated by a comma, and an input set as "02,05" would return all items related to these two numbers : "A3,A7,A9".

i have achieved this in Google Sheets with the following formula :

=JOIN(","; UNIQUE(FILTER(A:A; ARRAYFORMULA(REGEXMATCH(","&B:B&","; ",("&SUBSTITUE(C2; ","; "|")&"),")))))

Where :

  • column A corresponds to the Item List
  • column B corresponds to the component List
  • Cell C2 is where I write my input

This formula works perfectly but I need to have the equivalent on excel for other purposes, and I didn't manage to "convert" this formula without the same functions as in Google Sheets.

There are some ways I found on the net that can output all matching items for a given component but they don't implement the possibility of having multiple inputs separated by a comma.

Would anyone have any idea of how I can do it ? Thank you in advance.

答案1

得分: 1

这是一个选项:

How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?

单元格 E2 中的公式:

=TEXTJOIN(",,",,REPT(A2:A12,ISNUMBER(FIND(B2:B12,D2))))

或者,更加动态但速度更快的方式:

=TEXTJOIN(",,",,REPT(TOCOL(A:A,1),ISNUMBER(FIND(TOCOL(B:B,1),D2))))

对于唯一值,可以使用以下公式:

=TEXTJOIN(",,",,UNIQUE(REPT(TOCOL(A:A,1),ISNUMBER(FIND(TOCOL(B:B,1),D2)))))

这应该有效,因为您已经将每个数字格式化为 '##' 格式。

英文:

Here is one option:

How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?

Formula in E2:

=TEXTJOIN(",",,REPT(A2:A12,ISNUMBER(FIND(B2:B12,D2))))

Or, more dynamic, but fast:

=TEXTJOIN(",",,REPT(TOCOL(A:A,1),ISNUMBER(FIND(TOCOL(B:B,1),D2))))

And, for UNIQUE() values:

=TEXTJOIN(",",,UNIQUE(REPT(TOCOL(A:A,1),ISNUMBER(FIND(TOCOL(B:B,1),D2)))))

This should work since you have formatted each number to the '##' format.

答案2

得分: 1

=TEXTJOIN(",",,FILTER(A2:A12,1-ISNA(XMATCH(B2:B12,TEXTSPLIT(D2,",",)))))

英文:

Another:

=TEXTJOIN(",",,FILTER(A2:A12,1-ISNA(XMATCH(B2:B12,TEXTSPLIT(D2,",")))))

答案3

得分: 1

以下是翻译好的部分:


• Formula used in cell E2

=TEXTJOIN(",",,REPT(A2:A12,TEXTSPLIT(D2,",")=B2:B12))


编辑:对于唯一值:

=TEXTJOIN(",",,UNIQUE(TOCOL(REPT(A2:A12,TEXTSPLIT(D4,",")=B2:B12))))


• Formula used in cell E2

=ARRAYTOTEXT(FILTER(A2:A12,ISNUMBER(XMATCH(B2:B12,TEXTSPLIT(D2,",")))))


或者,

=LET(
a,N(TEXTSPLIT(D2,",")=B2:B12)*ROW(B1:B11),
b,TOCOL(IF(a=0,NA(),a),3),
TEXTJOIN(",",,INDEX(A2:A12,b)))


英文:

Here is another alternative:

How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?


• Formula used in cell E2

=TEXTJOIN(", ",,REPT(A2:A12,TEXTSPLIT(D2,",")=B2:B12))

Edit: For UNIQUE Values:

=TEXTJOIN(", ",,UNIQUE(TOCOL(REPT(A2:A12,TEXTSPLIT(D4,",")=B2:B12))))

How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?


• Formula used in cell E2

=ARRAYTOTEXT(FILTER(A2:A12,ISNUMBER(XMATCH(B2:B12,TEXTSPLIT(D2,,",")))))

Or,

How can I search for all items which references match an input that can be multiple reference separated by a comma in excel?


=LET(
       a,N(TEXTSPLIT(D2,",")=B2:B12)*ROW(B1:B11),
       b,TOCOL(IF(a=0,NA(),a),3),
       TEXTJOIN(", ",,INDEX(A2:A12,b)))

huangapple
  • 本文由 发表于 2023年6月22日 20:15:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531790.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定