Excel IF statement check

Soldato
Joined
26 Aug 2005
Posts
6,884
Location
London
I have the following statement to see if C3 contains quotes or square brackets

=IF(SEARCH("""",C3,1),"quotes",IF(SEARCH("[",C3,1),"brackets","na"))

But it doesn't seem to work if I C3= dfg[

Any ideas?
 
Soldato
Joined
5 Dec 2010
Posts
3,207
Location
deep space nine
this'll test for brackets but I'm struggling with the quotes

=IF(MID(C3,SEARCH("[",C3,1),1)="[","Brackets","No Brackets")

this returns quotes

=MID(C3,SEARCH("""",C3,1),2)

but when I put it in an IF statement it's giving me a value error. I've even tried testing it against a helper cell so putting "" in H7 say and testing whether it is equal to the chars returned by the MID function and it gives me TRUE but can't get it to work in an IF yet.

This will test for Quotes

=IF(COUNT(FIND(CHAR(34),C3)),"Quotes","Not Quotes")

but for the life of me I cannot get the two statements to work together in an IF
 
Last edited:
Soldato
Joined
25 Oct 2002
Posts
2,642
It's not working because SEARCH is returning an error in the first part of the IF so it's never reaching the second stage of the IF to check for the bracket.

You can make it work by checking if an error has occurred, and if it hasn't assume that SEARCH has found the value you're interested in.

Something like this
Code:
=IF(NOT(ISERR(SEARCH("""",A1))),"Quotes",IF(NOT(ISERR(SEARCH("[",A1))),"Brackets","Nothing"))
 
Back
Top Bottom