formula to compare two strings

pwl2706

Board Regular
Joined
Mar 12, 2013
Messages
60
Hi,

we have a bunch of strings comprising of characters "A","B"..."Z" (and no others). A typical string looks like <CODE>ABZYC</CODE>. The strings are given in pairs like <CODE>ABC</CODE>, <CODE>ABDC</CODE>.

The strings are match if one string is contained in the other (i.e either one of the two strings contain all the alphabets of the other). The order in which the string appears don't matter.

Code:
[FONT=Courier New]ACBD[/FONT],<CODE>AC</CODE> - <CODE>Match</CODE>
<CODE>ACBD</CODE>,<CODE>CA</CODE> - <CODE>Match</CODE>
<CODE>ACBD</CODE>,<CODE>ADB</CODE> - <CODE>Match</CODE>
<CODE>AC</CODE>,<CODE>ABCD</CODE> - <CODE>Match</CODE>
<CODE>ABC</CODE>, <CODE>ABD</CODE> - <CODE>No Match</CODE>

so, is there a formula way of doing that, or is it VBA only?

thanks
Philip

PS - I did something in VBA, but wondered if there was a lovely formula solution?
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Welcome to the Board!

This would work, but note the last scenario. I don't know what you would want for that, but I assume No Match, but maybe you cannot have a scenario like that?
Excel Workbook
ABC
1ACDBACMatch
2ACDBCAMatch
3ACDBABCDMatch
4ACDBABCDMatch
5ACBCABDNo Match
6AAAAMatch
Sheet2
#VALUE!
 
Upvote 0
Note that what I have posted are array formulas and would need to be confirmed with control+shift+enter.
 
Upvote 0
Actually I noticed that my values didn't match exactly to the table you provided, here is an updated formula that looks both ways:
Excel Workbook
ABC
1ACDBACMatch
2ACDBCAMatch
3ACDBABDMatch
4ACABCDMatch
5ACBCABDNo Match
6AAAAMatch
Sheet2
#VALUE!
 
Upvote 0

Forum statistics

Threads
1,215,988
Messages
6,128,142
Members
449,426
Latest member
revK

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