Use Lookup formula with the MID function

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,152
Hi All,

I have a cell with i.e., 1C571 and based on the 4th number I would like to return a string (in this case it would be TS). Here is the formula I have come up with, but can't seem to get it to work. The MID function pulls the 7 but for the {5,7,9} I am getting {FALSE, FALSE, FALSE}. Maybe there is even a better way?

Code:
=IF(OR(MID(D2,4,1)={5,7,9}),LOOKUP(MID(D2,4,1),{5,7,9},{"SS","TS","SMS"}),"")
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi All,

I have a cell with i.e., 1C571 and based on the 4th number I would like to return a string (in this case it would be TS). Here is the formula I have come up with, but can't seem to get it to work. The MID function pulls the 7 but for the {5,7,9} I am getting {FALSE, FALSE, FALSE}. Maybe there is even a better way?

Code:
=IF(OR(MID(D2,4,1)={5,7,9}),LOOKUP(MID(D2,4,1),{5,7,9},{"SS","TS","SMS"}),"")

Try wrapping your MID in the function VALUE:

Code:
=IF(OR(VALUE(MID(D2,4,1))={5,7,9}),LOOKUP(VALUE(MID(D2,4,1)),{5,7,9},{"SS","TS","SMS"}),"")

When you use LEFT, RIGHT, MID, etc. it converts any number to text. In your original formula you were comparing the text value to a numric value so it will always return false.
 
Upvote 0
You could edit your formula to be this:
Code:
=IF(OR(MID(D2,4,1)={"5","7","9"}),LOOKUP(MID(D2,4,1),{"5","7","9"},{"SS","TS","SMS"}),"")
or....this works:
Code:
=INDEX({"","SS","TS","SMS"},MAX((MID(D2,4,1)={"5","7","9"})*{1,2,3})+1)

Does that help?
 
Upvote 0
Hi All,

I have a cell with i.e., 1C571 and based on the 4th number I would like to return a string (in this case it would be TS). Here is the formula I have come up with, but can't seem to get it to work. The MID function pulls the 7 but for the {5,7,9} I am getting {FALSE, FALSE, FALSE}. Maybe there is even a better way?

Code:
=IF(OR(MID(D2,4,1)={5,7,9}),LOOKUP(MID(D2,4,1),{5,7,9},{"SS","TS","SMS"}),"")

Jeff,

Try to coerce the text numbers...

=IF(OR(MID(D2,4,1)+0={5,7,9}),LOOKUP(MID(D2,4,1)+0,{5,7,9},{"SS","TS","SMS"}),"")
 
Upvote 0
Thanks to all. That's what I was forgetting the 4th character was not a number. I went with Ron's formula because all the other's would return #VALUE! where there was not a match.

Again, many thanks...
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

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