VBA or Formula to find (#3 and #4 digit) MOST match key (defined key)

aanisnaini

New Member
Joined
Dec 30, 2021
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Dear All,
as per subject, I'M looking forward to have your help to make VBA or Formula to to find (#3 and #4 digit) MOST match key (defined key). Attached the file and example the goal (just write one alphabet where is the most matched key).

- the goal is explained at second yellow highlighted, looking for the most key matched with each column number (just find #3 and #4digit).
example: in cell A2 (1221), looking for 21 match with what a KEYS?. if match with more than one key, then calculate which one the most (large/top) one.
- there is row with describe:
1. All Data key: index and match all data(number-just find #3 and #4digit) from A2 to Today
2. 1 month Key: index and match data(number-just find #3 and #4digit) from Today - one month (past)
3. 2 week key: index and match data(number-just find #3 and #4digit) from Today - 2 week (past)
4. 3 week key: index and match data(number-just find #3 and #4digit) from Today - 3 week (past)
5. 10 days key: index and match data(number-just find #3 and #4digit) from Today - 10 days (past)
6. 7 days key: index and match data(number-just find #3 and #4digit) from Today - 7 days (past)
that's why in A1..CQ1 value is date.

Thank you
looking for key.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQBRBSBTBUBVBWBXBYBZCACBCCCDCECFCGCHCICJCKCLCMCNCOCPCQCRCSCTCUCVCWCXCY
101/10/202102/10/202103/10/202104/10/202105/10/202106/10/202107/10/202108/10/202109/10/202110/10/202111/10/202112/10/202113/10/202114/10/202115/10/202116/10/202117/10/202118/10/202119/10/202120/10/202121/10/202122/10/202123/10/202124/10/202125/10/202126/10/202127/10/202128/10/202129/10/202130/10/202131/10/202101/11/202102/11/202103/11/202104/11/202105/11/202106/11/202107/11/202108/11/202109/11/202110/11/202111/11/202112/11/202113/11/202114/11/202115/11/202116/11/202117/11/202118/11/202119/11/202120/11/202121/11/202122/11/202123/11/202124/11/202125/11/202126/11/202127/11/202128/11/202129/11/202130/11/202101/12/202102/12/202103/12/202104/12/202105/12/202106/12/202107/12/202108/12/202109/12/202110/12/202111/12/202112/12/202113/12/202114/12/202115/12/202116/12/202117/12/202118/12/202119/12/202120/12/202121/12/202122/12/202123/12/202124/12/202125/12/202126/12/202127/12/202128/12/202129/12/202130/12/202131/12/202101/01/202202/01/202203/01/2022KEYKey Number
212216261686712559301725745389457767506683339956441758288736197265907270346615201914521444827960894649464769672163485196791849340362781829128993991913228077592763583068779073377324846205153495978448547087860850867142106476584218844809991501204782545380211861212785684986961824556194893439829356948334032985306748910752131050059216109771848674522037059635567370261880000A012345
3#N/A0B012346
4#N/AC012347
5Looking for #3 and #4 Digit Most Match key FORMULAD012348
6All data KeyE012349
71 Month KeyF012356
82 week keyG012357
93 week keyH012358
1010 Days KeyI012359
117 days KeyJ012367
12K012368
13The Goal: Looking for #3 and #4 Digit MOST Match keyL012369
14All data KeyAM012378
151 Month KeyYN012379
162 week keyZO012389
173 week keyAAP012456
1810 Days KeyWWQ012457
197 days KeyXXR012458
20S012459
21T012467
22U012468
23V012469
24W012478
25X012479
26Y012489
Sheet1 (2)
Cell Formulas
RangeFormula
CQ3CQ3=VALUE(CW1)
CM3CM3=INDEX($CS$1:$CS$199,MATCH(MID(CM2,2,1),$CT$1:$CT$199,0),1)
CM4CM4=VLOOKUP(MID(CM2,3,1),CS1:CY2,CT1:CY2,TRUE)
CS2:CS26CS2=LEFT(ADDRESS(1, ROW(CS1), 4, TRUE), (ROW(CS1)>26)+1)
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:CQ2Expression=AND(ISODD(LEFT(RIGHT(A2;2);1));RIGHT(A2)="0")textNO
A2:CQ2Expression=AND(LEN(A2)>5)textNO
A2:CQ2Expression=AND(LEN(A2)<2)textNO
A2:CQ2Expression=AND(LEFT(RIGHT(A2;2);1)="8";ISEVEN(RIGHT(A2)))textNO
A2:CQ2Expression=AND(LEFT(RIGHT(A2;2);1)="8";ISODD(RIGHT(A2)))textNO
A2:CQ2Expression=AND(LEFT(RIGHT(A2;2);1)="0";ISEVEN(RIGHT(A2)))textNO
A2:CQ2Expression=AND(ISEVEN(LEFT(RIGHT(A2;2);1));RIGHT(A2)="0")textNO
A2:CQ2Expression=AND(RIGHT(A2)="8")textNO
A2:CQ2Expression=AND(LEFT(RIGHT(A2;2);1)="9")textNO
A2:CQ2Expression=AND(ISEVEN(LEFT(RIGHT(A2;2);1));RIGHT(A2)="0")textNO
A2:CQ2Expression=AND(LEFT(RIGHT(A2;2);1)="0";ISODD(RIGHT(A2)))textNO
A2:CQ2Expression=AND(ISEVEN(LEFT(RIGHT(A2;2);1));RIGHT(A2)="9")textNO
A2:CQ2Expression=AND(ISODD(LEFT(RIGHT(A2;2);1));RIGHT(A2)="9")textNO
A2:CQ2Expression=OR(LEFT(RIGHT(A2;2);1)="1";LEFT(RIGHT(A2;2);1)="2";LEFT(RIGHT(A2;2);1)="3";LEFT(RIGHT(A2;2);1)="4";LEFT(RIGHT(A2;2);1)="5";LEFT(RIGHT(A2;2);1)="6";LEFT(RIGHT(A2;2);1)="7";RIGHT(A2)="1";RIGHT(A2)="2";RIGHT(A2)="3";RIGHT(A2)="4";RIGHT(A2)="5";RIGHT(A2)="6";RIGHT(A2)="7")textNO
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA/Formula to find (#3 and #4 digit) MOST match key (defined key)
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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