need formula or macro to compare a number to the second digit and return the first digit(s) if there is(are) a match(es)

purelutz

New Member
Joined
May 11, 2014
Messages
16
Hello there, i'm wondering if this is possible. i need a formula that will output the below data in column E-G based on given data in cells a-c and cells h-j.
For example in E1, i want to take 0 from A1 and compare it to the right-most digit from h1-j1 and if there is a match return the first digit, which is 1.
column E is for looking up column A, column F is to look up column B, and G for C. if there are multiple instances then also output those as well. if no match then simply output nothing or "-".
Thank you.

1578625200502.png
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How about:

Book1
ABCDEFGHIJ
10121  131410
2012 1,2 11721
3012  34532
4012 1,3,5 13151
50122,3 2202230
sheet
Cell Formulas
RangeFormula
E1:G5E1=SUBSTITUTE(IF(""&A1=RIGHT($H1),","&LEFT($H1),"")&IF(""&A1=RIGHT($I1),","&LEFT($I1),"")&IF(""&A1=RIGHT($J1),","&LEFT($J1),""),",","",1)
 
Upvote 0
Dante may well have answered your question already, but can you confirm what result should be in F1 of your sample if cell I1 just contained "1" instead of '14"?
 
Upvote 0
thanks good formula but 1 thing, to peter_: if the cell contained 1 instead of 14 the result should be 0. any way to modify the formula so that if there is a single digit return 0 because it's implicit (5 vs 05) but excel may not pick up on this? thank you.
 
Upvote 0
if the cell contained 1 instead of 14 the result should be 0
Thanks, I thought that might be the case. However, I forgot to also ask you what version of Excel you are using.

If you have the TEXTJOIN function, then try this, copied across and down. (I have assume that 2 digits is the most that will appear in columns H:J)

Book1
ABCDEFGHIJ
10121  131410
2012 1, 2 11721
3012  34532
4012 0 651
50122, 3 2202230
Compare
Cell Formulas
RangeFormula
E1:G5E1=TEXTJOIN(", ",1,IF(RIGHT($H1:$J1,1)+0=A1,LEFT(TEXT($H1:$J1,"00"),1),""))
 
Upvote 0
thanks good formula but 1 thing, to peter_: if the cell contained 1 instead of 14 the result should be 0. any way to modify the formula so that if there is a single digit return 0 because it's implicit (5 vs 05) but excel may not pick up on this? thank you.

Try this:

Book1
ABCDEFGHIJ
10121  13110
2012 1,2 11721
3012  34532
4012 3,5 13151
50122,3 2202230
sheet
Cell Formulas
RangeFormula
E1:G5E1=SUBSTITUTE(IF(AND(LEN($H1)=2,""&A1=RIGHT($H1)),","&LEFT($H1),"")&IF(AND(LEN($I1)=2,""&A1=RIGHT($I1)),","&LEFT($I1),"")&IF(AND(LEN($J1)=2,""&A1=RIGHT($J1)),","&LEFT($J1),""),",","",1)
 
Upvote 0
If you have the TEXTJOIN function ..
.. otherwise try

Book1
ABCDEFGHIJ
10121  131410
2012 1, 2 11721
3012  34532
4012 0 651
50122, 3 2202230
Compare (2)
Cell Formulas
RangeFormula
E1:G5E1=MID(IF(RIGHT($H1,1)+0=A1,", "&INT($H1/10),"")&IF(RIGHT($I1,1)+0=A1,", "&INT($I1/10),"")&IF(RIGHT($J1,1)+0=A1,", "&INT($J1/10),""),3,7)
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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