Ask Your Question

How to use if statement to search for multiple strings?

asked 2016-09-02 21:31:31 +0200

AliZ gravatar image

Is it possible to use an if statement with multiple conditions? I have a large database and am searching for 12 words. If any of these 12 words appears in the column in question, I would like to return TRUE. How would I go about this? Is this a nested IF statement?

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted

answered 2016-09-03 03:43:07 +0200

mark_t gravatar image

Based on your last comment to Lupp you could use the MATCH function to check each cell of your list against a list of possible options and set the value of a helper column to true.


Where $E$2:$E$4 is a list of possible matches to return true. A2 is the first cell of your list and you copy this formula down the helper column.

As you suggested you can then filter on the value of this helper column.

edit flag offensive delete link more

answered 2016-09-03 07:25:39 +0200

pierre-yves samyn gravatar image


English is not my native language, but from what I understand, you do not need a function to get the result.

DataMore filtersAdvanced Filter can filter a range depending of another (containing the searched strings).

Cick Options if you want to copy the result elsewhere.

In Filter.ods example, Data (A7:B35) are filtered according to the filter cell range A1:A5.

More info. here


edit flag offensive delete link more

answered 2016-09-02 23:00:02 +0200

Lupp gravatar image

updated 2016-09-03 14:08:36 +0200

I cannot put the facts you mention together sensibly. You surely are talking of a certain part of a column (or more reasonable a row.)
A column has up to 2^20-1 elements. You cannot search that huge number again and again. IF (or the new IFS) will not help much.
You can try an "array-formula" accumulating by OR the matches that may exist. (I would prefer to count these matches by SUM.)
The attached example demonstrates the OR-ing or counting of matches for three single letters (replacing your words) in 4 adjacent cells in a row per dataset.
(Editing: Replaced first attachment with a better one.)

(Editing with respect to the second comment by @AliZ below)
You are right. Neither is English my native language nor is my English actually sufficient. Nonetheless I try to understand your OQ now as "...I would like to return a TRUE per row in an extra column to allow for filtering by the results... Is this a nested IF statement? "
No. IF is not at the heart of the solution. It may occur in formulae, however.
The task as modified above is easy in a sense. @pierre-yves samyn and @mark_t already posted working solutions. There may be additional expectations concerning the solution, not explicitly posted by the OQ yet. ...
A solution not only creating the selecting values, but also doing the filtering by formulae is attached.

edit flag offensive delete link more


Hmm. Not sure how to be clearer. Maybe this example helps? I really appreciate the help, but not sure the array-formula will work. For example, I have a database with 5000+ rows. Column P lists fruits. If a cell in that column contains apples, bananas, pears, or oranges, I would like that to be replaced with TRUE. Is there a way to do this with an IF statement? Such as =IF(P1:P5000; "apples, bananas, pears, oranges", TRUE)

AliZ gravatar imageAliZ ( 2016-09-02 23:50:25 +0200 )edit

I cannot imagine a solution using IF. Why?
I do not understand the new usage of the word "replace".
(I also do not understand in what way the information you are trying to get should be useful. A real database would SELECT WHERE and count the results. An established way to mimic SQL with data collections in spreadsheets is the usage of helper columns. Anyway a more exact knowledge of the actual problem is indispensable to be able to give valuable advice.)

Lupp gravatar imageLupp ( 2016-09-03 00:23:09 +0200 )edit

I'm guessing English is not your native language, so I'm sorry if my explanation is hard to grasp. I will try again, however, because you seem to want to help. (Maybe?) I need to save all of the rows that contain either "apples, bananas, pears or oranges" in Column P. I figured that if I marked all of these as TRUE, then I could easily apply a filter and get all of the Column P TRUE items. I really would just like to know if you can use an IF statement with multiple conditions in Calc.

AliZ gravatar imageAliZ ( 2016-09-03 01:05:02 +0200 )edit

answered 2016-09-03 00:46:45 +0200

m.a.riosv gravatar image

Another way to do it, I think. With COUNTIF that needs to use regular expressions if the calc option for search criteria on the whole cell is enable, that is recommended because there is a bug being slow search for text with some functions like VLOOKUP.

image description


edit flag offensive delete link more


Thanks. Not trying to count the items, but mark them as TRUE (either by changing their current cell contents or in another column). Appreciate the advice, though!

AliZ gravatar imageAliZ ( 2016-09-03 01:07:53 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-09-02 21:31:31 +0200

Seen: 2,393 times

Last updated: Sep 03 '16