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
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.

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

DanteAmor

Well-known Member

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)

Peter_SSs

MrExcel MVP, Moderator
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"?

purelutz

New Member
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.

Peter_SSs

MrExcel MVP, Moderator

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),""))

DanteAmor

Well-known Member
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)

Peter_SSs

MrExcel MVP, Moderator
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)

Replies
2
Views
1K
Replies
6
Views
270
Replies
1
Views
176
Replies
7
Views
282
Replies
10
Views
579

1,126,888
Messages
5,621,416
Members
415,839
Latest member
Pollydooner

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.

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

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