# Sum values based on multiple words found in string of text

#### hartsie

##### Board Regular
Hello,

I have what I think to be a tricky VBA job.

I have two tables, one with single names, and the other with full names. I am going to assign a numerical sum based on the combination of single names found in full names. For example: Bob = 5, Michael = 6, Scott = 7. With name and number residing in two columns in one table. This is the "lookup" range. The other table contains full names. The column with full names would be range "Flname." When I perform a lookup, I would like to sum and post the results of the relative values in range "sumrng." So, the name in flname "Bob Michael Scott" would sum to 18, "Scott Michael" to 13, "Bob Scott" to 12, and "Michael Scott" to 13 in sumrng.

This seems like something that is possible in VBA... but I have searched the interwebs far and wide and I couldn't think of the best way to describe this for my search parameters.

If anyone knows if this is possible, please let me know. All you VBAers out there are truly talented people.

### Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

#### Fluff

##### MrExcel MVP, Moderator
You can do that with a simple formula

+Fluff New.xlsm
ABCDEFG
1
2Bob5Bob michael scott18
3Michael6Bob Scott12
4Scott7Scott Michael13
5
Main
Cell Formulas
RangeFormula
G2:G4G2=SUMPRODUCT((ISNUMBER(SEARCH(\$A\$2:\$A\$4,F2)))*(\$B\$2:\$B\$4))

#### hartsie

##### Board Regular
That is great! Thank you for sharing! I love the creative approach.

Thank you!

#### Fluff

##### MrExcel MVP, Moderator
You're welcome & thanks for the feedback.

#### hartsie

##### Board Regular

I love the formula. It is working exactly as I hoped it would work.

This is just my curiosity speaking out - do all excel formulas translate into VBA? Or, are there some combinations that don't?

#### Fluff

##### MrExcel MVP, Moderator
You can use VBA to insert any formula into a cell if that's what you mean.

Thank you

My pleasure.

#### hartsie

##### Board Regular
So... I am very grateful for your recommendation. The function works perfectly -- thank you. I was hoping that I could optimize it. I have two thousand lines in the typical file I am working with... and I have endless attributes. Therefore, it tends to get bogged down in the recalculation. I would say that, overall, this function will save me much time. However, I fear that as the list of attributes grows, my computer won't have the processing power to handle the sumproduct. Do you have suggestions for optimizing this function?

#### Fluff

##### MrExcel MVP, Moderator
As long as the formula is only looking a a few thousand rows, there should be no problem.

1,106,623
Messages
5,512,462
Members
408,898
Latest member
Glenno557