Sum values based on multiple words found in string of text

hartsie

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

Some videos you may like

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
Joined
Jun 12, 2014
Messages
44,906
Office Version
365
Platform
Windows
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
Joined
May 6, 2020
Messages
55
Office Version
2016
That is great! Thank you for sharing! I love the creative approach.

Thank you!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
44,906
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback.
 

hartsie

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
2016

ADVERTISEMENT

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
Joined
Jun 12, 2014
Messages
44,906
Office Version
365
Platform
Windows
You can use VBA to insert any formula into a cell if that's what you mean.
 

hartsie

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
2016

ADVERTISEMENT

Thank you
 

hartsie

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
2016
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
Joined
Jun 12, 2014
Messages
44,906
Office Version
365
Platform
Windows
As long as the formula is only looking a a few thousand rows, there should be no problem.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

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

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top