Assign Value to each word in a string

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182
I am looking to assign a value to words, then total the value. I am only coming up with solutions that add one value and not all of them.

Cat=1
Dog=2
Bird=3
Lizard=4

Example:

A "String"B "Solution"
1Cat Dog Bird6
2Dog2
3Bird Lizard7
4Cat Dog3

<tbody>
</tbody>









Thank you
 
Last edited:
Darn, even the improved version has some issues. Consider the string "Cat Cat". I modified the modified version to:

{=SUM(((LEN(" "&SUBSTITUTE(A2," "," ")&" ")-LEN(SUBSTITUTE(" "&SUBSTITUTE(A2," "," ")&" "," "&$D$2:$D$5&" ","")))/LEN(" "&$D$2:$D$5&" ")*$E$2:$E$5))}

and it seems to handle that case. Even so, I think JoeMo's UDF in #6 is probably the best choice. No worries about non-numeric data in E2:E5 for example.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Darn, even the improved version has some issues. Consider the string "Cat Cat.
What do you see that was wrong with the "improved" formula I posted in Message #9 with respect to "Cat Cat"? The value of Cat was 1 and "Cat Cat" evaluates to 2, 1 for each appearance of the word... isn't that what you would expect it to do?
 
Upvote 0
Right, I expect to see 2, but when I put the #9 formula in B2 I get 1:

ABCDEF
1String#9 formuladifferent versionWordValue#11 formula
2Cat Cat12Cat12
3Dog22Dog22
4Bird Lizard77Bird37
5Cat Dog33Lizard43

<tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
B2{=SUM(((LEN(" "&A2&" ")-LEN(SUBSTITUTE(" "&A2&" "," "&$D$2:$D$5&" ","")))/LEN(" "&$D$2:$D$5&" ")*$E$2:$E$5))}
C2{=SUM(((LEN(" "&A2&" ")-LEN(SUBSTITUTE(" "&A2&" ",$D$2:$D$5&" ","")))/LEN($D$2:$D$5&" ")*$E$2:$E$5))}
F2{=SUM(((LEN(" "&SUBSTITUTE(A2," "," ")&" ")-LEN(SUBSTITUTE(" "&SUBSTITUTE(A2," "," ")&" "," "&$D$2:$D$5&" ","")))/LEN(" "&$D$2:$D$5&" ")*$E$2:$E$5))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>




If I only append a space to the end of the D2:D5 words, I get the formula in C2 and I get a result of 2. And F2 shows the formula I proposed in post #11.
 
Upvote 0

Forum statistics

Threads
1,216,049
Messages
6,128,496
Members
449,455
Latest member
jesski

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