Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SQL "IN" Function in Excel

Tags:

excel

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") 
like image 436
Juan Velez Avatar asked Dec 23 '11 16:12

Juan Velez


People also ask

How do I use SQL query in Excel?

Connecting SQL to the main Excel window The main Excel window is the one you use every time you open Excel. To load data from SQL Server, go to Data – Get Data – From Database – From SQL Server Database. This has superseded previously used methods such as Microsoft Query. You will then have to provide the Server Name.


2 Answers

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"

like image 120
Mikeb Avatar answered Oct 04 '22 07:10

Mikeb


=IF(OR(A1={"word1","word2","word3","word4","word5"}),"YES","NO") 
like image 38
RonnieDickson Avatar answered Oct 04 '22 08:10

RonnieDickson