Comparing 2 strings - 70% the same

Ragnar1211

Well-known Member
Joined
Jul 10, 2008
Messages
572
I am attempting to compare two different strings and find out how similar they are. I really am not sure how to approach it --- i want to compare a string like this:

RETAIL PURCHASE 805011644964;Point Of Sale or Debit Card

and this

RETAIL PURCHASE 837001001025;Point Of Sale or Debit Card

and say they are similar enough - like 80% or something like that.

Is there any vba magic out there that does this?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
It entirely depends on how you want to compare it.

If your entries can be logically separated into groups and then analyzed by section, then it's probably possible. If you just want a blanket similarity score then you'd have to decide how you want the algorithm to work.

For instance, if the exact same entry is written in reverse order, is that similar? All the characters are the same, but the order will only be similar for the middle. Or if 'Retail Purchase' is written as 'Purchase Retail' -- the words are totally dissimilar if you look word-by-word, but they are probably the same thing in reality. If you use the same logic for numbers, however, you would end up saying account number 12345678 is the same as 56781234, which is probably not the case.
 
Upvote 0
I think as long as the words are the same I could do the following with an array:

1) split the string I want to lookup into pieces - the words
2) use instr to compare
3) create a score of the results - eg if 5/6 words are found then etc.

Does that make sense?
 
Upvote 0
Yes, it does. However, if you have less than 6 words, or a word is misspelled, then you may run into problems. I don't know what your data looks like or how you get it.
 
Upvote 0

Forum statistics

Threads
1,207,111
Messages
6,076,614
Members
446,216
Latest member
BEEALTAIR

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