How to find the fourth digit and return a specific text

MMyslenski

New Member
Joined
Apr 11, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Someone showed me this at my last job but I can't remember it. I am trying to write a formula that will look at the fourth digit of a number, and then based on what that number is, return a specific text. As an example, if I had the following cells
A B
1 1234 Bill
2 4321 Bob
3 6789 Sally
4 9786 Sam

the formula would say "If in cell X, the fourth digit is 4, type Bill, if its 1, type Bob, if its 9, type Sally, if its 6, type Sam" I hope that makes sense. I searched this site for the last 15 minutes and found similar formulas but not exactly what I am looking for.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi & welcome to MrExcel.
How about
Excel Formula:
=SWITCH(MID(A2,4,1)+0,1,"Bob",4,"Bill",6,"Sam",9,"Sally","")
 
Upvote 0
Hi & welcome to MrExcel.
How about
Excel Formula:
=SWITCH(MID(A2,4,1)+0,1,"Bob",4,"Bill",6,"Sam",9,"Sally","")
That worked!

I have a follow up question; is there a way to check multiple columns for input? as an example:

1234​
Bill
4321​
Bob
6789​
Sally
9786​
Sam

So if column A has data, do the look up, but if column A has no data, look in column B for data, if theres no data there, check column C. Is it possible to do multiple column look ups?
 
Upvote 0
How about
Excel Formula:
=LET(CL,IF(A2<>"",A2,IF(B2<>"",B2,C2)),SWITCH(MID(CL,4,1)+0,1,"Bob",4,"Bill",6,"Sam",9,"Sally",""))
 
Upvote 0
How about
Excel Formula:
=LET(CL,IF(A2<>"",A2,IF(B2<>"",B2,C2)),SWITCH(MID(CL,4,1)+0,1,"Bob",4,"Bill",6,"Sam",9,"Sally",""))
Amazing! This is the greatest website ever, and you are a top notch, wonderful human being. This was so helpful

IF you have the time, because I like to learn, if you could explain in small detail (so I can maybe figure it out on my own in the future) what each step of the function is doing, I would be extremely appreciative. If that's too much, at least I have the formula and can use it.

Thank you again. You've saved hundreds of hours in manual labor someone was doing before.
 
Upvote 0
This part is storing the value of A2, B2 or C2 in the variable CL IF(A2<>"",A2,IF(B2<>"",B2,C2)) then then this gets the 4th character & converts from text to a number MID(CL,4,1)+0 and the Switch function then switches the values.
 
Upvote 0

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

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