IF OR with ISTEXT

Chialiwa

New Member
Joined
Feb 15, 2018
Messages
27
I'm trying to write a formula that says if the 8th character in my string (from the left) is either the number 1 or a letter, then return the left 8 characters, if not, return the left 7. However, when I use this it always returns 8 characters no matter what. What am I doing wrong? (I'm entering this formula in cell A1):

=IF(OR(LEFT(B1,8)=1,ISTEXT(LEFT(B1,8))),LEFT(B1,8),LEFT(B1,7))

Thank you!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Board!

LEFT(B1,8)
actually returns 8 characters, not 1

If you want to return the 8th character only, use:
MID(B1,8,1)

Armed with this new knowledge, see if you can update your formula.

 
Upvote 0
I want to return all 8 if the 8th character is the number "1" or a letter. If not, then I want it to return the first 7 characters.
 
Upvote 0
I want to return all 8 if the 8th character is the number "1" or a letter. If not, then I want it to return the first 7 characters.
I understand. But you are checking one character (the 8th character) in your condition, and then deciding whether to return 7 or 8 characters based on that.
So, in your two conditions in your OR clause, you need to change that to use the MID function like I showed instead of LEFT.
You would would continue to use LEFT in your TRUE and FALSE clauses after that.
 
Last edited:
Upvote 0
Also, I thought maybe it was the first part of the formula, so I changed it, but it still only returns 8 instead of 7

=IF(OR(MID(B1,7,1)=1,ISTEXT(MID(B1,7,1))),LEFT(B1,8),LEFT(B1,7))
 
Upvote 0
Chialiwa, Good afternoon.

Joe4, Greetings from Brazil.

Try to use:

=IF(OR(--MID(B1,8,1)=1,MID(B1,8,1)>=CHAR(65)),LEFT(B1,8),LEFT(B1,7))

Is thaat what you want?

I hope it helps.
 
Last edited:
Upvote 0
Here is a slightly different approach you can try...

=LEFT(A1,8-(ISNUMBER(0+MID(SUBSTITUTE(A1,1,"X"),8,1))))
 
Upvote 0
Hi Marcilio,

That works for the ones with the letters, but not for the ones with the number 1 as the 8th character. I ran a test formula on my data and I think the problem is that it is picking up all of the 8th characters as text (even though there is just a number there). Not sure how to fix that.

Chialiwa, Good afternoon.

Joe4, Greetings from Brazil.

Try to use:

=IF(OR(MID(B1,8,1)=1,MID(B1,8,1)>=CHAR(65)),LEFT(B1,8),LEFT(B1,7))

Is thaat what you want?

I hope it helps.
 
Upvote 0

Forum statistics

Threads
1,213,533
Messages
6,114,179
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top