Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel function to return characters before second occurrence of a specified character

Tags:

excel

I want a function to return the first two names in a cell for example

"Jones, Anna Mary" will return "Jones Anna"

I tried =LEFT(A1, FIND(" ",A1)-1) but it returns only Jones.

Thanks

like image 896
user1442459 Avatar asked Aug 31 '12 20:08

user1442459


2 Answers

You could get everything before the 2nd space by using this version

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

That would still include the comma so if you don't want that you can add a SUBSTITUTE function to remove commas, i.e.

=SUBSTITUTE(LEFT(A1,FIND(" ",A1,FIND(" ",A1)+1)-1),",","")

like image 70
barry houdini Avatar answered Oct 11 '22 19:10

barry houdini


=LEFT(SUBSTITUTE(A1," ","-",2),FIND("-",SUBSTITUTE(A1," ","-",2),1)-1)

I used the SUBSTITUTE() function to replace the second space with a hyphen. I then used the FIND() function on the SUBSTITUTE string.

like image 20
AxGryndr Avatar answered Oct 11 '22 18:10

AxGryndr