Using SQL “IN” Function in Excel

2020-02-26 03:39发布

Is there an "IN" type function like the one used in sql that can be used in excel? For example, if i am writing an If statement in excel and I want it to check the contents of a cell for 5 different words can i write something like:

=If(A1=IN("word1","word2","word3","word4","word5"),"YES","NO")

标签: excel
2条回答
小情绪 Triste *
2楼-- · 2020-02-26 03:52
=IF(OR(A1={"word1","word2","word3","word4","word5"}),"YES","NO")
查看更多
走好不送
3楼-- · 2020-02-26 04:05

You could use MATCH :

=MATCH(A1, {"word1","word2","word3","word4","word5"}, 0) 

which will return the index of the matching item in the array list. The trailing 0 means it should be an exact match. It will return #N/A if it isn't there, so you can tag a IF(ISNA( onto the front to make it behave like your "IN":

=IF(ISNA(MATCH(A1, {"word1","word2","word3","word4","word5"}, 0)),"NO","YES")

Note the change in order of the "YES" and "NO"

查看更多
登录 后发表回答