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
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,619
Office Version
  1. 2007
Platform
  1. Windows
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)
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows
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
Joined
May 11, 2014
Messages
16
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
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
Joined
Dec 3, 2018
Messages
12,619
Office Version
  1. 2007
Platform
  1. Windows
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
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,127,597
Messages
5,625,724
Members
416,130
Latest member
galgozzi

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
Top