+ Reply to Thread
Results 1 to 5 of 5

How to compare the similarity of 2 cells?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    23

    Question How to compare the similarity of 2 cells?

    Hi guys, I want to compare the similarity of the 4-digit primary SIC code of an acquirer, and the 4-digit primary SIC code of a target. It's for my Master's thesis.

    If the first digit of each code doesn't match: similarity = 0
    If the first digit of each code matches: similarity = 1
    If the two first digits of each match: similarity = 2
    If the three first digits of each matches: similarity = 3
    If the all the digits of each code matches: similarity = 4

    What is the right formula?

    Example:

    Acquirer SIC Target SIC Similarity
    1896 1896 4
    1963 1900 2
    6952 6327 1
    5369 5369 4
    6321 6312 2
    Last edited by glux; 07-29-2012 at 03:43 AM. Reason: Problem solved!

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,047

    Re: How to compare the similarity of 2 cells?

    try this formula...

    =IF(LEFT(A1,4)=LEFT(B1,4),4,IF(LEFT(A1,3)=LEFT(B1,3),3,IF(LEFT(A1,2)=LEFT(B1,2),2,1)))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,408

    Re: How to compare the similarity of 2 cells?

    This seems to work:

    =IF(A1=B1,4,IF(LEFT(A1,3)=LEFT(B1,3),3,IF(LEFT(A1,2)=LEFT(B1,2),2,IF(LEFT(A1)=LEFT(B1),1,0))))

    Hope this helps.

    Pete

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,228

    Re: How to compare the similarity of 2 cells?

    Hi glux,

    FDibbins was short a zero so his formula was close but not exact. See the attached with another way to get the answer using:
    =IF(H2=I2,4,IF(INT(H2/10)=INT(I2/10),3,IF(INT(H2/100)=INT(I2/100),2,IF(INT(H2/1000)=INT(I2/1000),1,0))))
    It looks like Pete found the error also and improved it. Because you say the problem has only digits my formula does the same thing.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Registered User
    Join Date
    02-03-2012
    Location
    Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: How to compare the similarity of 2 cells?

    MarvinP... Your formula is correct!!! Thanks all of you 3 for helping me!!! I'm sooo grateful!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1