我有一个if语句,用于搜索单元格以查看它是否包含多个值中的一个,如果该值存在,则显示另一个单元格中的值。
因此,在单元格A1
中,我有以下代码:
=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),CONCATENATE(HYPERLINK(AV10)),"")
此代码搜索G10
,SLR
和SMR
的单元格BRL
。
如果该值存在,则它显示来自单元格AV10
我想添加一个or-statement,这样我就可以有多个这样的if语句
=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),CONCATENATE(HYPERLINK(AV10)),""), OR,
IF(COUNT(SEARCH({"TTT","RRR","BBB"},G10)),CONCATENATE(HYPERLINK(AV11)),""), OR,
IF(COUNT(SEARCH({"ZZZ","XXX","YYY"},G10)),CONCATENATE(HYPERLINK(AV12)),""), OR,
IF(COUNT(SEARCH({"LLL","MMM","QQQ"},G10)),CONCATENATE(HYPERLINK(AV11)),""), OR,
IF(COUNT(SEARCH({"UUU","KKK","PPP"},G10)),CONCATENATE(HYPERLINK(AV13)),""),"ERROR")
所以,我们这里有一个大的if语句,它检查一个单元格是否包含一组三个值"SLR", "SMR", OR "BRL"
,如果它确实显示了AV10中的链接,并且单元格中是否包含这些三个值,但inStead包含"TTT", "RRR", "BBB"
,然后显示AV11
中的值,依此类推
有人可以帮我解决这个问题吗?
提前致谢
答案 0 :(得分:1)
执行此操作的常规方法是使用下一个if语句替换if语句的else部分中的空字符串。然后单词ERROR位于最后一个if语句的最后一个。像这样:
=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),CONCATENATE(HYPERLINK(AV10)),
IF(COUNT(SEARCH({"TTT","RRR","BBB"},G10)),CONCATENATE(HYPERLINK(AV11)),
IF(COUNT(SEARCH({"ZZZ","XXX","YYY"},G10)),CONCATENATE(HYPERLINK(AV12)),
IF(COUNT(SEARCH({"LLL","MMM","QQQ"},G10)),CONCATENATE(HYPERLINK(AV13)),
IF(COUNT(SEARCH({"UUU","KKK","PPP"},G10)),CONCATENATE(HYPERLINK(AV14)),
"ERROR")))))
我不知道为什么你在那里有CONCATENATE功能 - 它连接它的参数但是它们每个只有一个参数所以它实际上没有做任何事情。除非我不理解你做了什么,否则这应该做同样的事情:
=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),HYPERLINK(AV10),
IF(COUNT(SEARCH({"TTT","RRR","BBB"},G10)),HYPERLINK(AV11),
IF(COUNT(SEARCH({"ZZZ","XXX","YYY"},G10)),HYPERLINK(AV12),
IF(COUNT(SEARCH({"LLL","MMM","QQQ"},G10)),HYPERLINK(AV13),
IF(COUNT(SEARCH({"UUU","KKK","PPP"},G10)),HYPERLINK(AV14),
"ERROR")))))
如果AV10包含=HYPERLINK("\\UKSH000-FILE06\Purchasing\New Supplier Set-Ups\assets\EMAIL_PLANT.msg","Send Email")
,则公式=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),HYPERLINK(AV10),"")
会生成“发送电子邮件”字样的超链接,但点击它们不是有效地址。
所以你真正想做的是将AV10更改为=HYPERLINK("\\UKSH000-FILE06\Purchasing\New Supplier Set-Ups\assets\EMAIL_PLANT.msg")
或\\UKSH000-FILE06\Purchasing\New Supplier Set-Ups\assets\EMAIL_PLANT.msg
并更改我给你的论坛:
=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),HYPERLINK(AV10,"Send Email"),
IF(COUNT(SEARCH({"TTT","RRR","BBB"},G10)),HYPERLINK(AV11,"Send Email"),
IF(COUNT(SEARCH({"ZZZ","XXX","YYY"},G10)),HYPERLINK(AV12,"Send Email"),
IF(COUNT(SEARCH({"LLL","MMM","QQQ"},G10)),HYPERLINK(AV13,"Send Email"),
IF(COUNT(SEARCH({"UUU","KKK","PPP"},G10)),HYPERLINK(AV14,"Send Email"),
"ERROR")))))
现在,计算出的超链接显示为“发送电子邮件”,但具有正确的地址(当您将鼠标悬停在单元格上时,可以在工具提示中看到该地址)。如果您不想让AV10-AV14显示实际地址,并且您希望它们显示发送电子邮件,那么公式需要提取AV10-AV14中超链接的地址。
根据http://blog.contextures.com/archives/2010/12/13/get-the-url-from-an-excel-hyperlink/,没有内置函数,但如果在该页面上添加VBA函数,则AV10可以保留为=HYPERLINK("\\UKSH000-FILE06\Purchasing\New Supplier Set-Ups\assets\EMAIL_PLANT.msg","Send Email")
,您的公式将如下所示:
=IF(COUNT(SEARCH({"SLR","SMR","BRL"},G10)),HYPERLINK(HLink(AV10),"Send Email"),
IF(COUNT(SEARCH({"TTT","RRR","BBB"},G10)),HYPERLINK(HLink(AV11),"Send Email"),
IF(COUNT(SEARCH({"ZZZ","XXX","YYY"},G10)),HYPERLINK(HLink(AV12),"Send Email"),
IF(COUNT(SEARCH({"LLL","MMM","QQQ"},G10)),HYPERLINK(HLink(AV13),"Send Email"),
IF(COUNT(SEARCH({"UUU","KKK","PPP"},G10)),HYPERLINK(HLink(AV14),"Send Email"),
"ERROR")))))
现在一切都显示发送电子邮件,但所有超链接都应该有效。