Finding and comparing length after locating a special character
I'm trying to find a hyphen in a word and compare the length of the word left after the hyphen.
For example:
Mary-Bell has a hyphen in it. I want to take everything after the hyphen (length of four) and compare it to be greater than or equal to seven in length. Bell is less than seven in this case so it would ideally trigger the "length < 7" function.
My code:
(to find if the last half of the name is > 6)
IF(AND(ISERROR(FIND("-",B5,1))=FALSE, LEN(MID(B5,FIND("-",B5)+1,99)>6),
(to find if the last half of the name is < 7)
IF(AND(ISERROR(FIND("-",B5,1))=FALSE,LEN(MID(B5,FIND("-",B5)+1,99)<7),
Unfortunately, right now this is giving me an error. How do I find the length of the remainder of a word after using MID to get the position to start in the middle?
**Edit: Got my initial issue sorted.
Posted Sep 10, 2012, 10:23 AM UTC · edited
I believe the problem is with your parenthesis at the end of the LEN function. It should look like this instead:
With an additional closed parenthesis before the < or > signs.
Those came up as TRUE and FALSE when I put them for Mary-Bell.
Hope that solves it!
=LOWER(
IF(AND(ISERROR(FIND("-",B5,1))=TRUE,LEN(B5)>6),
LEFT(B5,99),
IF(AND(ISERROR(FIND("-",B5,1))=TRUE,LEN(B5)<7),
CONCATENATE(B5,LEFT($E$3,7-LEN(B5))),
IF(AND(ISERROR(FIND("-",B5,1))=FALSE,LEN(MID(B5,FIND("-",B5)+1,99))>6,
MID(B5,FIND("-",B5)+1,99),
IF(AND(ISERROR(FIND("-",B5,1))=FALSE,LEN(MID(B5,FIND("-",B5)+1,99))<7,
CONCATENATE(MID(B5,FIND("-",B5)+1,99),LEFT($E$3,7-LEN(B5))), 1)))))
This is the entirety of my code. I tried making the changes you suggest but it's still error-ing out. The formatting is just for readability.
**Edit: I figured out part of the issue.
***Edit: Figured out the formatting. Now I'm just having a problem with the very last line in the code. Thanks for the help!