How to keep a tally of matching letters in separate cells

Davenil

New Member
Joined
May 19, 2024
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
Hey Everyone,

I was hoping I could get a little help with a small project I was trying to work on for fun. I’m trying to come up with a series of 20 four letter words that have similar letters in order to create a kind of “Mastermind” guessing game. Kind of similar to the Hacking minigame in the Fallout series works. The idea is you are trying to guess the correct word. After picking one of the 20 words, you’d then see how many letters are in the correct spot. You won’t know which letters are correct, just that 0, 1, 2, or 3 letters are correct out of 4.

For example, if the secret word, is FEAR and you guess TIRE, none of the letters are in the correct spot. So, you’ll see 0. If your next guess is FAIL, you’ll see a 1 because of the F. Next guess might be DEAR, so you’ll see 3. And so on, eventually allowing you to narrow it down to the one correct word.

The problem is I don’t know a good array of words that would make for a good guessing puzzle. To try and help, I was hoping to create an excel spreadsheet that would at least give me an idea of what words have a certain amount of matching letters. I just don’t know how to create a function that compares multiple cells and keeps track of how many cells in multiple rows match specified column cells.

What I was trying to do is create a 4x20 table of cells with letters in each cell. Each row would then spell a 4 letter word. There would be a table next to it that then keeps track of how many of the other rows contain words that have 0, 1, 2, and 3 matching letters in the same columns.

In the picture I attached, I have 20 rows of words just as examples. B2 to E21 contains letters that spell out 20 different words. To try and explain what I mean, I started with the top row, B2:E2, which spells FEAR and compared all the other rows. I put how many letters are in the correct spot along the A column. So, B3:E3 has FAIL, only the F is in the correct spot, so I put a 1. B4:E4 is FOOT, so it’s also only the F that’s correct. B6:E6 has SEAL in the row, because the E and the A are in the correct spot I put a 2 in the A column.

Then, in columns F through I, I added up how many words had 0, 1, 2, and 3 matches. Basically, how many 0’s, 1’s, 2’s, and 3’s are in Column A. The problem is that it would take forever to do every single word manually. Especially if I wanted to try doing 5 or 6 letter words. So, I was hoping there might be a simple formula for doing all this automatically? If the formula worked correctly, cell K2 would have the number 9 in it, cell L2 would have a 7, M2 would have a 2, and N2 would have a 1.

I’m pretty new to excel, so I don’t know all the capabilities. I was thinking maybe a Countif or Countifs function could work, but that just counts all the cells that match the value. I don’t know how to count cells that don’t match the value. Plus, I don’t want to keep a tally of how many times ANY of the letters match in the entire word. I need it to compare each cell of each row to letters in the same columns of each of those other rows. I was thinking maybe combining Countif with an IF statement to try and first check if the row has a matching letter in the correct column, then adding 1 to a tally, then do it again with the second letter of the next column, and so on. But I feel like that function would be dozens of lines long having separate functions to check each and every cell individually. That might be more work than just doing it all manually. I don’t know how to do just a sweeping check of an entire column and counting separately for each row. If you get what I mean? And how would that translate to maybe a 5x20 table or 6x20 table?

Ideally it would be comparing text in a specified cell and not just a specific letter too. The idea being that I could change a letter in one of the cells and it would automatically update all of the counts. Maybe instead of an S in the cell B6 to spell SEAL, I want to change it to a D, making DEAL. That would have a pretty big cascade effect on the matching counts of all the other words, which would take forever to go back through manually and redo all the numbers. So, it’d be nice if there were formulas that did it automatically.

I hope all of that wasn’t super confusing. If you have any questions or need clarification, just let me know and I’ll do my best. Any ideas or help would be greatly appreciated.

Thanks,
Dave
 

Attachments

  • matching letters.png
    matching letters.png
    82.1 KB · Views: 21

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Here is a solution to the first parts of your question anyway.

The letters comparison in column A can be done with a series of comparisons of the contents of the cells to their "parent" to give a true/false or 1/0 value, which you then sum.
The values in column F:I then count the occurrences of the respective values. I only did seven words but you get the picture.

Book1
ABCDEFGHI
10123
2fear1311
31fail
41foot
51fire
62seal
73dear
84fear
90shin
Sheet1
Cell Formulas
RangeFormula
F2:I2F2=COUNTIFS($A$3:$A$9,F$1)
A3:A9A3=SUM(B3=$B$2,C3=$C$2,D3=D$2,E3=E$2)


Regarding a list of words, as a suggestion I would probably put a list of words on another hidden sheet, and then generate a random number in Excel to choose the word. Then do the comparisons against that hidden word. If you need help to do this let me know.
 
Upvote 0
Here is a solution to the first parts of your question anyway.

The letters comparison in column A can be done with a series of comparisons of the contents of the cells to their "parent" to give a true/false or 1/0 value, which you then sum.
The values in column F:I then count the occurrences of the respective values. I only did seven words but you get the picture.

Book1
ABCDEFGHI
10123
2fear1311
31fail
41foot
51fire
62seal
73dear
84fear
90shin
Sheet1
Cell Formulas
RangeFormula
F2:I2F2=COUNTIFS($A$3:$A$9,F$1)
A3:A9A3=SUM(B3=$B$2,C3=$C$2,D3=D$2,E3=E$2)


Regarding a list of words, as a suggestion I would probably put a list of words on another hidden sheet, and then generate a random number in Excel to choose the word. Then do the comparisons against that hidden word. If you need help to do this let me know.
Yea, that could work. I guess the only issue would be how would I compare each row individually? The only way using this method would be to create a separate column for every row, so I'd have to have 20 columns counting each row. I tried it with a couple columns and it does seem to work good enough. If I wanted to expand to something like a 5x20 or 6x20, I would just have to add extra columns to account for the new rows.

I do have to go in and change row numbers and column numbers in the formulas because I'm not sure how to get it to work with the "$" signs and dragging the equations to other cells. But that's not that big of a deal.
 

Attachments

  • matching letters 2.png
    matching letters 2.png
    88.7 KB · Views: 12
Upvote 0
I don't understand what you mean by
I guess the only issue would be how would I compare each row individually? The only way using this method would be to create a separate column for every row, so I'd have to have 20 columns counting each row.
What rows are you trying to compare, and why do you need a column for each one?

Regarding $ symbols - the $ sign "locks" the row or column it precedes.
So, A1 dragged to B2 will change to B2 (both the row and column change)
$A1 dragged to B2 will change to $A2 (only the row changes)
A$1 dragged to B2 will change to B$1 (only the column changes)
$A$1 dragged to B2 will remain as $A$1 (neither the row nor column change)
 
Upvote 0
I don't understand what you mean by

What rows are you trying to compare, and why do you need a column for each one?

Regarding $ symbols - the $ sign "locks" the row or column it precedes.
So, A1 dragged to B2 will change to B2 (both the row and column change)
$A1 dragged to B2 will change to $A2 (only the row changes)
A$1 dragged to B2 will change to B$1 (only the column changes)
$A$1 dragged to B2 will remain as $A$1 (neither the row nor column change)
I'm trying to make a comparison of each row with all the others. So, basically exactly what your formulas are doing, just with every single row. It really didn't take too long to add a bunch of columns and throw them all into a group that I can minimize.
 

Attachments

  • matching letters 3.png
    matching letters 3.png
    110.9 KB · Views: 12
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,344
Members
452,638
Latest member
Oluwabukunmi

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