简体   繁体   English

Excel:在单元格中搜索多个术语并返回找到的值

[英]Excel: Searching for multiple terms in a cell and return the found value

I am trying to scan a column and search for terms inside a cell. 我正在尝试扫描列并在单元格内搜索术语。 Once any of these terms are found, place the found one in another cell. 一旦找到这些术语中的任何一个,将找到的一个放在另一个单元格中。

The terms are in a named range, I call it "namedrangeOfApps" with over 400 rows. 这些术语在一个命名范围内,我称其为“ namedrangeOfApps”,具有超过400行。

This is what I have now but instead of returning TRUE I want to return the actual value found. 这就是我现在所拥有的,但是我不想返回TRUE,而是想返回找到的实际值。

 =SUMPRODUCT(--ISNUMBER(SEARCH({"namedrangeOfApps"},G2)))>0 

Example of a cell could be: 单元格的示例可以是:

"Microsoft.Office.v.21" In this case, if either Microsoft and or Office is found" Place the found entry in another Cell instead of just placing TRUE. “ Microsoft.Office.v.21”在这种情况下,如果找到Microsoft和Office,则将找到的条目放置在另一个单元格中,而不仅仅是TRUE。

Source of original solution 原始解决方案的来源

With text in cell A1 try: A1单元格中输入文字:

=IF(ISNUMBER(SEARCH("Office ",A1)),"Office","") & IF(ISNUMBER(SEARCH("Adobe ",A1)),"Adobe","") & IF(ISNUMBER(SEARCH("google ",A1)),"google","") & IF(ISNUMBER(SEARCH("Microsoft ",A1)),"Microsoft","")

在此处输入图片说明

While it does appear a little "brute force", it is easy to understand and will return more than one keyword if more than one keyword is present. 尽管确实出现了一些“蛮力”,但它易于理解,如果存在多个关键字,则返回多个关键字。

EDIT#1: 编辑#1:

Here is a small User Defined Function. 这是一个小的用户定义函数。 Its arguments are the cell being searched and a list of keywords (in the sample, it is a Named Range called "mikee" in column C ) : 它的参数是要搜索的单元格和关键字列表(在示例中,它是C列中名为“ mikee”的命名范围)

Option Explicit
Public Function RetrieveKeys(rin As Range, KeyList As Range) As String
    Dim s As String, r As Range

    s = rin(1).Text
    RetrieveKeys = ""
    For Each r In KeyList
        If InStr(1, s, r.Value) > 0 Then RetrieveKeys = RetrieveKeys & r.Value
    Next r
End Function

在此处输入图片说明

It can handle a very large list of keywords and if a separator is required between multiple returns, it is easy to change. 它可以处理很大的关键字列表,如果在多个返回之间需要分隔符,则很容易更改。

try this 尝试这个

=IFERROR(INDEX({NamedRange1},MATCH(TRUE,ISNUMBER(SEARCH({NamedRange1},A10)),0)),"")

or 要么

=IFERROR(INDEX({"microsoft", "google", "apple"},MATCH(TRUE,ISNUMBER(SEARCH({"microsoft", "google", "apple"},A10)),0)),"")

This works great 这很棒

reference... 参考...

Searching for multiple text strings in a MS Excel cell and return the same string when found 在MS Excel单元格中搜索多个文本字符串,并在找到时返回相同的字符串

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

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