Match using Left Right function

cshetty

Board Regular
Joined
Apr 15, 2017
Messages
76
Office Version
  1. 2016
Platform
  1. Windows
Dears

In column A I have list of unique codes and I want to get the code based on input of last 4 characters of the code. Please help me to get a formula.

e.g., There is a code in cell A5, which is 80007458 and in input cell when I enter 7458, I should get the full code in result cell.

Theoretically the equation should be
INDEX (A1:A100, MATCH (input value, RIGHT (A1:A100,4),0))

Thank you
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try changing your formula to:
INDEX (A1:A100, MATCH (input value, RIGHT (A1:A100,4)*1,0))

The RIGHT function is going to return text. My guess is you are entering 7458 as a number, so you aren't getting a match. By multiplying the RIGHT function by 1 it will change to a numeric value.
 
Upvote 0
Try changing your formula to:
INDEX (A1:A100, MATCH (input value, RIGHT (A1:A100,4)*1,0))

The RIGHT function is going to return text. My guess is you are entering 7458 as a number, so you aren't getting a match. By multiplying the RIGHT function by 1 it will change to a numeric value.
So this should be an array formula, right ? Works now. Thanks
 
Upvote 0
You could also use VLOOKUP, or MOD which avoids any text/numerical conversions. I assume both will still require array entry in your version. Perhaps the AGGREGATE version does not require array entry though?

BTW, if marking a post as the solution, please mark the post that actually provided the solution. So here I have change the mark from post 3 to post 2.

22 11 08.xlsm
ABCDEF
1Code
2800074557458800074588000745880007458
380007456
480007457
580007458
680007459
780007460
880007461
get code
Cell Formulas
RangeFormula
D2D2=VLOOKUP("*"&C2,A1:A100&"",1,0)+0
E2E2=INDEX(A2:A10,MATCH(C2,MOD(A2:A10,10000),0))
F2F2=AGGREGATE(15,6,A2:A10/(MOD(A2:A10,10000)=C2),1)
 
Upvote 0
Solution
Peter Sir,

trying to understand this formula, how it worked
=AGGREGATE(15,6,A2:A10/(MOD(A2:A10,10000)=C2),1)
15 = Small
6 = Ignore error
A2:A10/(MOD(A2:A10,10000)=C2) = This part i am not getting it. Please help me to understand better,
 
Upvote 0
Peter Sir,

trying to understand this formula, how it worked
=AGGREGATE(15,6,A2:A10/(MOD(A2:A10,10000)=C2),1)
15 = Small
6 = Ignore error
A2:A10/(MOD(A2:A10,10000)=C2) = This part i am not getting it. Please help me to understand better,
If I am not wrong , (MOD(A2:A10,10000)=C2) is to ascertain True or false so that when we devide the code by the result of this formula, either returns error or the code we are looking for. All other results in an error , so the smallest one is the one we are looking for.

Thank you Sir.
 
Upvote 0
(MOD(A2:A10,10000)=C2) is to ascertain True or false so that when we devide the code by the result of this formula, either returns error or the code we are looking for.
Looks like you have figured it out. (y)
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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