0

How can I use the find function to see if two strings exist in excel?

EX:

row/column  A        B       C     D
       1    fly     cat    dog    fish
       2    cat    pig    horse   dog
       3    zebra  pig     cat    elephant

I want to search what rows both contains cat and dog. How can I achieve this?

2
  • 1
    I can give you a formula without using the find function. Will that work? Does case matter? Commented Jul 17, 2015 at 1:14
  • 1
    @pnuts - surely "complex" is a subjective term - what's complex for me might not be for you or vice versa - in my view that makes the term "complex formula development" not particularly useful, especially as those asking, normally by definition, don't know the answer! Commented Jul 17, 2015 at 11:54

4 Answers 4

2

How about use AND,COUNTIF function together:

=AND(COUNTIF(A1:D1,"cat"),COUNTIF(A1:D1,"dog"))

If the row contains both cat and dog,it returns TRUE.

Sign up to request clarification or add additional context in comments.

6 Comments

This is actually the best way to write the formula.
Right. When I wrote the comment here, I was more just referring to how overly complicated my formula is and how simple this formula is.
@pnuts That is exactly what I did (separate search terms out) in my answer :)
It was to convert a geeky number (0/1/2) into text for readability and potentially filtering
Ok - I accept anchoring wasn't absolutely necessary. I also get you can produce TRUE/FALSE like that - both work equally well - but using the IF provides a more user-friendly output.
|
1

If the formula returns a 1, the row contains both cat and dog. If it returns 0, at least one is missing from the row:

=SUMPRODUCT(MAX(--(A1:D1="cat"))*MAX(--(A1:D1="dog")))

2 Comments

@rwilson This doesn't seem to work. Even when I edit it for a bigger file that A:D. It just always returns 0.
The formula didn't work when used on the sample above? The formula only looks for an exact match. If a row contains the word "dogs", searching for "dog" with this formula won't return a match.
0

If you really love find function,though it seemed longer.

=AND(FIND("cat",CONCATENATE(A1,"|",B1,"|",C1,"|",D1)),FIND("dog",CONCATENATE(A1,"|",B1,"|",C1,"|",D1)))

Separator | is important!

cat + dog = catdog

ca + tdog = catdog

But add separator |(or other) will not:

cat + |+ dog = cat|dog

ca + | + tdog= ca|tdog

Note that find is case-sensitive. If not case-sensitive you can use search function.

Comments

0

If you are happy to run a formula on each line, then you could copy this down and check for a value of "2".

=IF(AND(COUNTIF($A3:$D3,"cat")>0,COUNTIF($A3:$D3,"dog")>0),"Found them","")

You could replace the literals for a cell reference so that you can easily change out your search words. Maybe something like this:

=IF(AND(COUNTIF($A3:$D3,$F$1)>0,COUNTIF($A3:$D3,$G$1)>0),"Found them","")

2 Comments

But =2 potentially gives some false positives (what if there are 2 dogs) or the opposite (what if there are 2 dogs and 1 cat?)
Well spotted @barryhoudini! I have revised my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.