Home » excel » excel – Comparing how many letters match

excel – Comparing how many letters match

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to compare two cells in Excel to retrieve a numeric value, for example:

Trial type   Duration    Letters shown   Distracters    Laterality   Response  Full  
 6           80          XZHTEJ          0              Bilateral    TEHZ

In that line I would like to compare the letters shown with the response, and return a number for how many are correct. I would like it to have the number 4, as there are four letters typed that match the letters shown.

How to&Answers:

VBA might be more suitable but you have not tagged as such and a formula should work:

=IFERROR(FIND(MID(C1,1,1),F1)>0,0)+IFERROR(FIND(MID(C1,2,1),F1)>0,0)+IFERROR(FIND(MID(C1,3,1),F1)>0,0)+IFERROR(FIND(MID(C1,4,1),F1)>0,0)++IFERROR(FIND(MID(C1,5,1),F1)>0,0)+IFERROR(FIND(MID(C1,6,1),F1)>0,0)

Answer:

@pnuts’ answer works if Letters Shown (in C1) is always 6 or fewer characters.

The following will work if Response (in F1) is always 4 or fewer characters:

=LEN(C1)-
 LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(
     C1,MID(F1,1,1),""),MID(F1,2,1),""),MID(F1,3,1),""),MID(F1,4,1),"")
 )

Either method can easily be expanded as needed.

Answer:

Just FYI, here is a solution for any length of response. It also has the advantage of being shorter than the other given solutions (I think)

{=SUM(IF(ISERROR(MATCH(MID(F1,ROW(INDIRECT("B1:B"&LEN(F1))),1),MID(C1,ROW(INDIRECT("A1:A"&LEN(C1))),1),0)),0,1))}

It’s an array formula so leave out the curly braces and enter the formula using Ctrl+Shift+Enter

The solution creates two arrays like below

Shown      Inputted
 X          T
 Z          E
 H          H
 T          Z
 E
 J

And then loops through each of the Inputted characters looking for a match in the Shown array and returning a 1 if there is a match, otherwise a 0. Finally the SUM adds all of the 1’s (matches) to give the required result.