Home > Software design >  Finding partial matches within an if statement
Finding partial matches within an if statement

Time:08-26

Does anyone know how I can write an if statement that searches for partials in VBA? For example, if A2 and A3 both contain Jon, I would like the totals under the 2020 column to be summed, and then it would move down and check the values in A4 and A5. It should work the same way for Mary. But with ben, it should only total A6 because the cell underneath contains Chip. Then it should go down again and check the following two cells for a match. This is for a report that changes weekly, so the names will not always be the same. Any help is appreciated. Thank you.

enter image description here

CodePudding user response:

As Rno said, name uniques would become an issue, but for this small data set you can add another column of name values in column F and do a sumif formula on those separated names. See Formulas Used Pic

In cell f2 =TRIM(RIGHT(A2,LEN(A2)-FIND("-",A2,1)))

In cell H2 =SUMIF($F:$F,$G2,B:B)

  • Related