2

I have pasted text in cell A1 that may look like this:

"Vanguard - Total Market - Composite" or "Vanguard - Total Market - Commingled"

I want to cut off the " - Composite" or " - Commingled" and return the rest in cell B1. Currently I'm using this formula in B1:

=LEFT(A1,FIND(" - Composite",A1)-1)

However, I can't figure out how to look for multiple terms (i.e. Composite or Commingled). Is there a formula that could accomplish this? If not, how could I do it in VBA?

Thanks for the help!

JordanN
  • 45
  • 1
  • 7

3 Answers3

3

If I understand correctly, you're simply looking to strip everything past the second occurrence of -, i.e. returning the trimmed (extra whitespace removed) text left of the first - character. Adapting this solution to locate the last word in the string, this would be it:

=TRIM(SUBSTITUTE(LEFT(A1,LEN(A1)-LEN(MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"-",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))+1,LEN(A1)))),"-","",2))

This formula will work with or without the spaces around the -, and regardless of what follows:

formula in action


If even spacing is important, you can wrap it with SUBSTITUTE functions:

=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(LEFT(A1,LEN(A1)-LEN(MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"-",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))+1,LEN(A1)))),"-","",2)),"-"," - "),"  "," ")

And now you have clean, identically-formatted output for all cases:

even spacing

Community
  • 1
  • 1
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
1

I've made this formula that will work with many possibilities as long you fill the possibilities range, not needing to change the formula when there's a new one. Here it is:

=LEFT(A2,FIND(INDIRECT(ADDRESS(SUMPRODUCT((--ISNUMBER(SEARCH(Possibilities,A2)))*ROW(Possibilities)),SUMPRODUCT((--ISNUMBER(SEARCH(Possibilities,A2)))*COLUMN(Possibilities)))),A2)-1)

enter image description here

Marco
  • 1,279
  • 1
  • 15
  • 26
1

You can use the SUBSTITUTE function and chain multiple calls:

=SUBSTITUTE(SUBSTITUTE(A1," - Composite", ""), " - Commingled", "")
Community
  • 1
  • 1
JordanN
  • 45
  • 1
  • 7