Sum values based on multiple words found in string of text

hartsie

Board Regular
Joined
May 6, 2020
Messages
84
Office Version
  1. 2016
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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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))
 
Upvote 0
That is great! Thank you for sharing! I love the creative approach.

Thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
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?
 
Upvote 0
You can use VBA to insert any formula into a cell if that's what you mean.
 
Upvote 0
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?
 
Upvote 0
As long as the formula is only looking a a few thousand rows, there should be no problem.
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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