我需要修改以下公式以在特定单元格中搜索多个文本条件,如果匹配则返回各自的值。仅当我将其用于1个条件时它才起作用:
=IF(AND(ISNUMBER(SEARCH("text1",A2)),OR(ISNUMBER(SEARCH("text2",A2))),OR(ISNUMBER(SEARCH("text3",A2)))),"Category 1","No")
我还需要在同一公式中包含更多条件。我尝试使用以下公式,但无法正常工作:
=IF(AND(ISNUMBER(SEARCH("text1",A2)),OR(ISNUMBER(SEARCH("text2",A2))),OR(ISNUMBER(SEARCH("text3",A2)))),"Category 1","No") & IF(AND(ISNUMBER(SEARCH("text1",A2)),OR(ISNUMBER(SEARCH("text2",A2))),OR(ISNUMBER(SEARCH("text4",A2)))),"Category 2","No") & IF(AND(ISNUMBER(SEARCH("text1",A2)),OR(ISNUMBER(SEARCH("text6",A2))),OR(ISNUMBER(SEARCH("text4",A2)))),"Category 3","No")
如何修改以上内容以显示正确的类别编号?我需要在公式中添加大约20个不同的类别。
示例:
公式:
=IF(AND(ISNUMBER(SEARCH("London",A2)),OR(ISNUMBER(SEARCH("Luton",A2))),OR(ISNUMBER(SEARCH("Cardiff",AH3298)))),"Category 1","No") & IF(AND(ISNUMBER(SEARCH("London",A2)),OR(ISNUMBER(SEARCH("Luton",A2))),OR(ISNUMBER(SEARCH("Dublin",AH3298)))),"Category 2","No") & IF(AND(ISNUMBER(SEARCH("London",A2)),OR(ISNUMBER(SEARCH("Manchester",A2))),OR(ISNUMBER(SEARCH("Paris",AH3298)))),"Category 3","No")
提前谢谢!
答案 0 :(得分:2)
如果我正确推断了您的规则,那么以下方法可能适用于直接公式方法(但请参见下文):
=IF(AND(ISNUMBER(SEARCH({"London","Luton"},A2)),ISNUMBER(SEARCH("Paris",AH3298))),"Category 1",
IF(AND(ISNUMBER(SEARCH({"London","Luton"},A2)),ISNUMBER(SEARCH("Dublin",AH3298))),"Category 2",
IF(AND(ISNUMBER(SEARCH({"London","Manchester"},A2)),ISNUMBER(SEARCH("Cardif",AH3298))),"Category 3","No")))
但是,对于20个类别,您的公式大约需要2,000个字符。
使用表并为您的分类指定明确规则的方法将是可取的,因为将来它应该更容易维护。