IsNumber & Mid function

G

Guest

I have a cell (B2) that contains "RT3ERIDU"

I wrote a simple formula =IF(ISNUMBER(MID(B2,3,1)),LEFT(B2,3),LEFT(B2,2))

If the third character is a number I want to extract the first 3 characters
otherwise extract the first 2.

This isn't working and I don't understand why.
If I setup another cell with just the MID function then the cell displays
the number 3.

What am I missing here?
 
G

Guest

MID returns a string, so the isnumber function returns false, even if it's a
text representation of a number. I'd use iserror(value()) instead:
=if(iserror(value(mid(b2,3,1))),left(b2,2),left(b2,3))
If mid doesn't return a digit, then the isserror(value()) will be true and
this only returns two digits. Otherwise iserror is false and you get three
digits.
 
A

Alan

Another way,
=IF(ISNUMBER(MID(B2,3,1)*1),LEFT(B2,3),LEFT(B2,2))
the *1 forces the text value into a numerical value,
Regards,
Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MID / LEN 2
Generate Payment Due Date to exclude Weekends and Public Holiday 4
VLOOKUP and MID Function 9
Combining formulas 6
MID function results 3
Extracting part of a cell 6
=mid function 6
ISNUMBER 7

Top