简体   繁体   English

具有多个 if(isnumber(search)) 条件和 AND/OR 条件的 Excel 嵌套公式

[英]Excel nested formula with multiple if(isnumber(search)) criteria with AND/OR conditions

I need to modify the below formula to search for multiple text criteria, in the specific cell and returns the respective value if matches.我需要修改以下公式以在特定单元格中搜索多个文本条件,并在匹配时返回相应的值。 It does only work if I use it for 1 criteria:只有当我将它用于 1 个标准时,它才有效:

=IF(AND(ISNUMBER(SEARCH("text1",A2)),OR(ISNUMBER(SEARCH("text2",A2))),OR(ISNUMBER(SEARCH("text3",A2)))),"Category 1","No")

I also need to include more criteria's in the same formula.我还需要在同一公式中包含更多标准。 I tried to use the below formula but it doesn't work correctly:我尝试使用以下公式,但无法正常工作:

=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")

How to modify the above to display the correct category number?如何修改以上内容以显示正确的类别编号? I will need to add around 20 different categories in my formula.我需要在我的公式中添加大约 20 个不同的类别。

Example:例子:

在此处输入图片说明

Formula:公式:

=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")

Thank you in advance!先感谢您!

If I have deduced your rules correctly, then the following might work for a straight formula approach (but see below):如果我正确推断出您的规则,那么以下可能适用于直接公式方法(但请参见下文):

=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")))

However, for 20 categories, your formula would be about 2,000 characters long.但是,对于 20 个类别,您的公式长度约为 2,000 个字符。

An approach using a Table, with clear-cut rules for your categorization, would be preferable as it should be much easier to maintain in the future.使用表格的方法对您的分类有明确的规则,会更可取,因为将来维护起来会容易得多。

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

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