If a cell contains specific characters in specific positions, return another specified value

E_Tags

New Member
Joined
Oct 31, 2017
Messages
8
Can someone please help me with a formula to do the following? I can't find any previous solutions.

If a value from column A, features in any value in column C as the 3rd and 4th value, return the value from column B corresponding to the value in column A. Results being returned in column D.

:confused:


Column AColumn BColumn CColumn D
ABApples12XY9009
XYBananas35AB1221
DXPears96AB9875
FROranges89DX6854

<tbody>
</tbody>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi, welcome to the board :)

If I have understood correctly here is one option you can try, note - this isn't as robust as checking the 3rd and 4th characters specifically but maybe it is robust enough?


Excel 2013/2016
ABCD
1Column AColumn BColumn CColumn D
2ABApples12XY9009Bananas
3XYBananas35AB1221Apples
4DXPears96AB9875Oranges
5FROranges89DX6854#N/A
Sheet2
Cell Formulas
RangeFormula
D2=INDEX($B$2:$B$5,MATCH("*"&A2&"*",$C$2:$C$5,0))
 
Upvote 0
@MrExcel MVP, thank you for your response however I need it to only return when the values feature in that exact location as there will be the instance when those values could appear in column C in different positions but they are not relevant.


What does "*"&A2&"*" do?
 
Upvote 0
I need it to only return when the values feature in that exact location as there will be the instance when those values could appear in column C in different positions but they are not relevant.


Excel 2013/2016
ABCD
1Column AColumn BColumn CColumn D
2ABApples12XY9009Pears
3XYBananas35AB1221Apples
4DXPears96AB9875Oranges
5FROranges89DX6854#N/A
6AAGrapesAAZZ123Kiwi
7ZZKiwiZZAA123Grapes
Sheet2
Cell Formulas
RangeFormula
D2=LOOKUP(2,1/(MID($C$2:$C$7,3,2)=A2),$B$2:$B$7)


What does "*"&A2&"*" do?

The * characters are wild cards - so we are saying match anything & A2 & anything
 
Last edited:
Upvote 0
Excel 2013/2016
ABCD
1Column AColumn BColumn CColumn D
2ABApples12XY9009Pears
3XYBananas35AB1221Apples
4DXPears96AB9875Oranges
5FROranges89DX6854#N/A
6AAGrapesAAZZ123Kiwi
7ZZKiwiZZAA123Grapes
Sheet2
Cell Formulas
RangeFormula
D2=LOOKUP(2,1/(MID($C$2:$C$7,3,2)=A2),$B$2:$B$7)


The * characters are wild cards - so we are saying match anything & A2 & anything
You could have stayed with your original formula by just changing the first asterisk to two question marks...

=INDEX($B$2:$B$5,MATCH("??"&A2&"*",$C$2:$C$5,0))

Whereas an asterisk wildcard stands in for zero or more characters, a question mark wildcard stands in for exactly one character.
 
Last edited:
Upvote 0
You could have stayed with your original formula by just changing the first asterisk to two question marks...

=INDEX($B$2:$B$5,MATCH("??"&A2&"*",$C$2:$C$5,0))

Doh :oops: - thanks Rick.
 
Upvote 0
Thank you for your help on this, very much appreciated. This is definitely closer However why does D5 not return Pears?

I put the following formula into my actual sheet in the same format and it is returning #N/A for all in column D --> =INDEX($B$2:$B$105,MATCH(TRUE,INDEX(MID($C$2:$C$5,3,2)=A2,0),0))

My actual column C values are 25 characters and appear like so: FCCOSB-10000600-CR00MCW52
 
Upvote 0
However why does D5 not return Pears?

I think we (I) had the lookup the wrong way round, you can try..


Excel 2013/2016
ABCD
1Column AColumn BColumn CColumn D
2ABApples12XY9009Bananas
3XYBananas35AB1221Apples
4DXPears96AB9875Apples
5FROranges89DX6854Pears
6AAGrapesAAZZ123Kiwi
7ZZKiwiZZAA123Grapes
Sheet1
Cell Formulas
RangeFormula
D2=INDEX($B$2:$B$7,MATCH(MID(C2,3,2),$A$2:$A$7,0))
 
Upvote 0
I think I've created some confusion, let me explain what I want the results to communicate:

The values in Column C need to be coded based on what values appear as the 3rd and 4th characters. AA as the 3rd and 4th characters means apples, AB means Apples bananas, AC Apples Cake, etc.

If AB appears as the 3rd and 4th value in any value of Column C, it means that that row needs to be coded as Apples Bananas in Column D, and so on...


Column AColumn BColumn CColumn D
AAApplesFCABTG-09876543-75HY94HT7Apples Bananas
ABApples BananasFCASHT-67847565-748FHT867N/A
ACApples CakeFCAARG-72839465-846THFGR7Apples
ADApples DessertADBAYH-93647586-93JFT5867Banana Assort
BABanana AssortBABCWD-93748590-KFHG86756Banana Cake
BCBanana CakeGTABYH-01029384-93657FHT8Apples Bananas
BFBanana FruitYHADUY-08675465-94HDTRG67Apples Dessert

<tbody>
</tbody>

Any ideas? Apologies, my initial explanation allowed room for confusion.
 
Upvote 0

Forum statistics

Threads
1,215,860
Messages
6,127,378
Members
449,382
Latest member
DonnaRisso

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