Compare 2 alphanumeric strings (without spaces) and highlight the similar part

massi

New Member
Joined
Oct 4, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi everyone, I need to compare the strings contained in 2 adjacent columns (row by row) and highlight the similar part.

I tried with some VBA code I found online but it doesn't work well for me, as my strings don't contain any spaces or other characters.

I attach some of the lines.

Thank you all!!

Cartel1
AB
1Column 1Column 2
2pantotexsrlpantotex
3hgisrlabbigliamentohgi
4modamilanosrlmodamilanosrl
5bluediffusionsrlbluediffusion
6centromodaruggierobyarconfabbigliamentosumisuracentromoda2
7lafogliasrllafogliasrl
8franzeseabbigliamentosrlfranzeseabb
9euforiakajalproduzioneabbigliamentodonnabyfdpsrlfdpsrl
10stigmatieltdstigmati
11ghirafsrlghirafsrl
12cucitex2srlindumentiusaticucitex2011
13produzioneeingrossoabbigliamentodonnamonicamorellimonicamorelliofficial
14atelebabrideelenabarbaelenabarbasposa
15goldjeanssrlgoldjeans
16lauclecreazionidiguarinoannalaucle
17machodiffusion2ndstreetshowroommachodiffusion
18sitelliskinlaboutletrivadirenobolognasitellishop
19nuovaorizzontisrlorimodasrl
20soelservicesncditagliatielisaebenatisoniasoelservice
21ellebisrlalanellebi
22plissettaturacaporalidivalmorritomasecsasplissettaturacaporali
23confezionievieviconfezioni
24deantonicarniadacarnia
25gheshandgoldsrlcommercialegheshgold
26implosedabbigliamentouomoimplosed
27centrodecadecaroma
28dmyddmsrludmsrl17
29aretesrlaretemoda
30ingrossoabbigliamentosportivoroma100x100cotone100x100cotonesrls
31mpmartoranosrlmpmartoranosrl
32martinettireadivisescolasticheabitiprimacomunionemartinettirea
33lineaecostumelineacostume
34bliveblivepromozionale
35fashiontradesrlfashiontrade
36mffsrlmattmodafashionfursrlmffsrl
37futurasasdirizzivitoecfuturavitorizzi
38annarockmilanoannarockmilano
39almarsrlalmaringrossoabbigliamento
Foglio1
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi massi,

Welcome! Please provide some expected results. Which column is to be highlighted? Does the entire string from column B need to be found in column A? You do not want to match single letters right?

Thanks,

Doug
 
Upvote 0
Hi massi,

Welcome! Please provide some expected results. Which column is to be highlighted? Does the entire string from column B need to be found in column A? You do not want to match single letters right?

Thanks,

Doug

Hi Duggie and thanks for your help!

The column that needs to be highlighted is the second (B), in the image I also highlighted the first (in green) just to make you see the correspondence without effort.

You can see the expected result in the image. I understand that it can be complicated but maybe there is a way to set a minimum match of 3 consecutive characters (letters and numbers) so that it is detected and highlighted.
 

Attachments

  • sample.png
    sample.png
    51 KB · Views: 10
Upvote 0
I know this does not meet your results, but this is part way there...the formula in column C returns the three letter strings (generated from column B) that are found in column A. I am still thinking about the approach to writing this in VBA. It is for sure possible since I was able to generate these results. I might not be able to get to that until later today if I am lucky.
Book_2023-10-03.xlsx
ABCDEFGHIJKLMNOPQRSTU
1Column 1Column 2
2pantotexsrlpantotexpanantntotototetex
3hgisrlabbigliamentohgihgi
4modamilanosrlmodamilanosrlmododadamamimililalananonososrsrl
5bluediffusionsrlbluediffusionblulueuededidififfffufususisioion
6centromodaruggierobyarconfabbigliamentosumisuracentromoda2cenentntrtroromomomododa
7lafogliasrllafogliasrllafafofogoglgliliaiasasrsrl
8franzeseabbigliamentosrlfranzeseabbfrarananznzezeseseseaeababb
9euforiakajalproduzioneabbigliamentodonnabyfdpsrlfdpsrlfdpdpspsrsrl
10stigmatieltdstigmatistitigigmgmamatati
11ghirafsrlghirafsrlghihirirarafafsfsrsrl
12cucitex2srlindumentiusaticucitex2011cucucicititetexex2
13produzioneeingrossoabbigliamentodonnamonicamorellimonicamorelliofficialmononinicicacamamomororerelelllli
14atelebabrideelenabarbaelenabarbasposaelelenenanabababararbrba
15goldjeanssrlgoldjeansgololdldjdjejeaeanans
16lauclecreazionidiguarinoannalauclelauaucuclcle
17machodiffusion2ndstreetshowroommachodiffusionmacachchohododidififfffufususisioion
18sitelliskinlaboutletrivadirenobolognasitellishopsititetelellllilis
19nuovaorizzontisrlorimodasrlorisrl
20soelservicesncditagliatielisaebenatisoniasoelservicesoeoelelslseserervrvivicice
21ellebisrlalanellebiellllelebebi
22plissettaturacaporalidivalmorritomasecsasplissettaturacaporaliplilisissssesetettttatatatutururaracacacapapopororaralali
23confezionievieviconfezionievicononfnfefezezizioiononi
24deantonicarniadacarniacararnrninia
25gheshandgoldsrlcommercialegheshgoldgheheseshgolold
26implosedabbigliamentouomoimplosedimpmplplolososesed
27centrodecadecaromadececa
28dmyddmsrludmsrl17dmsmsrsrl
29aretesrlaretemodaareretete
30ingrossoabbigliamentosportivoroma100x100cotone100x100cotonesrls10000x0x1x1010000c0cocotototonone
31mpmartoranosrlmpmartoranosrlmpmpmamarartrtotororarananonososrsrl
32martinettireadivisescolasticheabitiprimacomunionemartinettireamarartrtitininenetettttitirirerea
33lineaecostumelineacostumelinineneacosoststutumume
34bliveblivepromozionaleblilivive
35fashiontradesrlfashiontradefasashshihioionontntrtraradade
36mffsrlmattmodafashionfursrlmffsrlmffffsfsrsrl
37futurasasdirizzivitoecfuturavitorizzifutututururavititorizizzzzi
38annarockmilanoannarockmilanoannnnanararorocockckmkmimililalanano
39almarsrlalmaringrossoabbigliamentoalmlmamar
6112292
Cell Formulas
RangeFormula
C2:H2,C39:E39,C38:N38,C37:K37,C36:F36,C35:L35,C34:E34,C33:J33,C32:M32,C31:N31,C30:M30,C28:E29,C27:D27,C26:H26,C25:G25,C24:F24,C23:K23,C22:U22,C21:F21,C20:K20,C19:D19,C18:H18,C17:N17,C16:F16,C15:I15,C14:J14,C13:M13,C12:H12,C11:I11,C10:H10,C9:F9,C7:K8,C6:J6C2=LET(searchstr,A2,str,B2,strLen,LEN(B2),str3s,TRANSPOSE(MID(B2,SEQUENCE(strLen-2),3)),FILTER(str3s,ISNUMBER(SEARCH(str3s,searchstr,1))))
Dynamic array formulas.

It is a start...hope that helps,

Doug
 
Upvote 0
I know this does not meet your results, but this is part way there...the formula in column C returns the three letter strings (generated from column B) that are found in column A. I am still thinking about the approach to writing this in VBA. It is for sure possible since I was able to generate these results. I might not be able to get to that until later today if I am lucky.
Book_2023-10-03.xlsx
ABCDEFGHIJKLMNOPQRSTU
1Column 1Column 2
2pantotexsrlpantotexpanantntotototetex
3hgisrlabbigliamentohgihgi
4modamilanosrlmodamilanosrlmododadamamimililalananonososrsrl
5bluediffusionsrlbluediffusionblulueuededidififfffufususisioion
6centromodaruggierobyarconfabbigliamentosumisuracentromoda2cenentntrtroromomomododa
7lafogliasrllafogliasrllafafofogoglgliliaiasasrsrl
8franzeseabbigliamentosrlfranzeseabbfrarananznzezeseseseaeababb
9euforiakajalproduzioneabbigliamentodonnabyfdpsrlfdpsrlfdpdpspsrsrl
10stigmatieltdstigmatistitigigmgmamatati
11ghirafsrlghirafsrlghihirirarafafsfsrsrl
12cucitex2srlindumentiusaticucitex2011cucucicititetexex2
13produzioneeingrossoabbigliamentodonnamonicamorellimonicamorelliofficialmononinicicacamamomororerelelllli
14atelebabrideelenabarbaelenabarbasposaelelenenanabababararbrba
15goldjeanssrlgoldjeansgololdldjdjejeaeanans
16lauclecreazionidiguarinoannalauclelauaucuclcle
17machodiffusion2ndstreetshowroommachodiffusionmacachchohododidififfffufususisioion
18sitelliskinlaboutletrivadirenobolognasitellishopsititetelellllilis
19nuovaorizzontisrlorimodasrlorisrl
20soelservicesncditagliatielisaebenatisoniasoelservicesoeoelelslseserervrvivicice
21ellebisrlalanellebiellllelebebi
22plissettaturacaporalidivalmorritomasecsasplissettaturacaporaliplilisissssesetettttatatatutururaracacacapapopororaralali
23confezionievieviconfezionievicononfnfefezezizioiononi
24deantonicarniadacarniacararnrninia
25gheshandgoldsrlcommercialegheshgoldgheheseshgolold
26implosedabbigliamentouomoimplosedimpmplplolososesed
27centrodecadecaromadececa
28dmyddmsrludmsrl17dmsmsrsrl
29aretesrlaretemodaareretete
30ingrossoabbigliamentosportivoroma100x100cotone100x100cotonesrls10000x0x1x1010000c0cocotototonone
31mpmartoranosrlmpmartoranosrlmpmpmamarartrtotororarananonososrsrl
32martinettireadivisescolasticheabitiprimacomunionemartinettireamarartrtitininenetettttitirirerea
33lineaecostumelineacostumelinineneacosoststutumume
34bliveblivepromozionaleblilivive
35fashiontradesrlfashiontradefasashshihioionontntrtraradade
36mffsrlmattmodafashionfursrlmffsrlmffffsfsrsrl
37futurasasdirizzivitoecfuturavitorizzifutututururavititorizizzzzi
38annarockmilanoannarockmilanoannnnanararorocockckmkmimililalanano
39almarsrlalmaringrossoabbigliamentoalmlmamar
6112292
Cell Formulas
RangeFormula
C2:H2,C39:E39,C38:N38,C37:K37,C36:F36,C35:L35,C34:E34,C33:J33,C32:M32,C31:N31,C30:M30,C28:E29,C27:D27,C26:H26,C25:G25,C24:F24,C23:K23,C22:U22,C21:F21,C20:K20,C19:D19,C18:H18,C17:N17,C16:F16,C15:I15,C14:J14,C13:M13,C12:H12,C11:I11,C10:H10,C9:F9,C7:K8,C6:J6C2=LET(searchstr,A2,str,B2,strLen,LEN(B2),str3s,TRANSPOSE(MID(B2,SEQUENCE(strLen-2),3)),FILTER(str3s,ISNUMBER(SEARCH(str3s,searchstr,1))))
Dynamic array formulas.

It is a start...hope that helps,

Doug
Thank you Doug!
 
Upvote 0
Hi Dugg, thinking about it carefully, I think that starting from column A where spaces are also included, it is easier to search for those words in the corresponding cells in column B. I attach the example sheet, thanks!

Cartel1
AB
1Column 1Column 2
2pantotex srlpantotex
3hgi srlabbigliamentohgi
4modamilano srlmodamilanosrl
5blue diffusion srlbluediffusion
6centromodaruggiero by arconf abbigliamento su misuracentromoda2
7la foglia srllafogliasrl
8franzese abbigliamento srlfranzeseabb
9euforiakajal produzione abbigliamento donna by fdp srlfdpsrl
10stigmati e ltdstigmati
11ghiraf srlghirafsrl
12cucitex 2 srl indumenti usaticucitex2011
13produzione e ingrosso abbigliamento donnamonica morellimonicamorelliofficial
14ateleba bride elena barbaelenabarbasposa
15gold jeans srlgoldjeans
16laucle creazioni di guarino annalaucle
17macho diffusion 2ndstreetshowroommachodiffusion
18sitelli skinlaboutlet riva di reno bolognasitellishop
19nuova orizzonti srlorimodasrl
20soel service snc di tagliati elisa e benati soniasoelservice
21ellebi srlalanellebi
22plissettatura caporali di valmorri tomas e c sasplissettaturacaporali
23confezioni evieviconfezioni
Foglio1
 
Upvote 0
Fast solution for a return of words found...VBA to highlight will take me more time than I have at the moment.
Book_2023-10-03.xlsm
ABCDEF
1Column 1Column 2Column 1 words found in Column 2
2pantotex srlpantotexpantotex
3hgi srlabbigliamentohgihgi
4modamilano srlmodamilanosrlmodamilanosrl
5blue diffusion srlbluediffusionbluediffusion
6centromodaruggiero by arconf abbigliamento su misuracentromoda2 
7la foglia srllafogliasrllafogliasrl
8franzese abbigliamento srlfranzeseabbfranzese
9euforiakajal produzione abbigliamento donna by fdp srlfdpsrlfdpsrl
10stigmati e ltdstigmatistigmati
11ghiraf srlghirafsrlghirafsrl
12cucitex 2 srl indumenti usaticucitex2011cucitex2
13produzione e ingrosso abbigliamento donnamonica morellimonicamorelliofficialemorelli
14ateleba bride elena barbaelenabarbasposaelenabarba
15gold jeans srlgoldjeansgoldjeans
16laucle creazioni di guarino annalauclelaucle
17macho diffusion 2ndstreetshowroommachodiffusionmachodiffusion
18sitelli skinlaboutlet riva di reno bolognasitellishopsitelli
19nuova orizzonti srlorimodasrlsrl
20soel service snc di tagliati elisa e benati soniasoelservicesoelservicee
21ellebi srlalanellebiellebi
22plissettatura caporali di valmorri tomas e c sasplissettaturacaporaliplissettaturacaporaliec
23confezioni evieviconfezioniconfezionievi
Sheet6
Cell Formulas
RangeFormula
C2:C3,C6,C8,C10,C16,C18:C19,C21,C23:D23,C22:F22,C20:E20,C17:D17,C11:D15,C9:D9,C7:E7,C4:D5C2=LET(searchwrds,TEXTSPLIT(A2," ",,TRUE,0,),searchstr,B2,IFERROR(FILTER(searchwrds,ISNUMBER(SEARCH(searchwrds,searchstr,1))),""))

Doug
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,262
Members
449,093
Latest member
Vincent Khandagale

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