I’ve encountered a situation where MID() is returning the expected value, but it seems to be the wrong “type”. For example, imagine you have a simple table of characters and their width in inches…
Char  Width
A  0.3465
B  0.3144
C  0.3478
...
In cell A1, I have the phrase F140
(my desired serial number).
In cell C2, I have the formula =INDEX(Widths,MATCH(C1,Chars,0))
.
When I manually type 1
in C1, the formula in C2 displays the width of that character as expected.
When I use a formula to find the character… =MID(A1,2,1)
… C1 displays the correct character (still 1
), but:

If the character is a letter, INDEX/MATCH works fine.

If the character is a number, INDEX/MATCH fails (???).

If the character is a number and I wrap the MID() like so:
VALUE(MID())
, INDEX/MATCH works fine. 
If the character is a letter and I wrap the MID() with
VALUE(MID())
, INDEX/MATCH fails.
Surely there is a way to accomplish this without knowing beforehand if MID() will return a number or letter?
Thanks,
B
MID returns text. If it looks like a number, it’s textthatlookslikeanumber, not a real number. You cannot use textthatlookslikeanumber to find a match in a column of real numbers. Thankfully, there’s the double unary or double minus that can covert textthatlookslikeanumber to a true number.
=MID(A1,2,1)
However that will throw an error if you are trying to convert true text (e.g. abc) to a number so an IFERROR wrapper must be applied to return either a true number (if possible) or text.
=iferror(MID(A1,2,1), MID(A1,2,1))
Tags: excelexcel, function