I have the following 3 rows of data in cells A1:A3
in Google Sheets:
Doe, Jane
Doe, Joe
John Doe
I want the following in B1:B3
:
Jane Doe
Joe Doe
John Doe
Essentially, I'm creating a new column with all names as FIRST_NAME LAST_NAME
.
My approach was to use split
,index
,concatenate
,find
,isnumber
,andif
, which works if I apply the function individually to each single cell:
= IF( ISNUMBER( find(",",A1)), concatenate(index(split(A1,", "),0,2)," ", index(split(A1,", "),0,1)),A1))
However, I want to repeat this function for each name in Column A using a single function in B1
.
I tried to simply use ArrayFormula
, but this (unsurprisingly) does not have the desired result:
= Arrayformula(IF( ISNUMBER( find(",",A1)), concatenate(index(split(A1,", "),0,2)," ", index(split(A1,", "),0,1)),A1)))
Resulting in:
JaneJoeDoe DoeDoeJohn
JaneJoeDoe DoeDoeJohn
John Doe
I'm too new to Google Sheets to know if there's a looping type approach to doing this. In R
, I would have this figured out in 15 seconds using an apply
function.
Best Answer
As we've have found, it's not difficult to write a formula to achieve this outcome. But an
ARRAYFORMULA
is another matter and it seems (famous last words!) that it easier said than done (assuming even that it is possible).I've looked at a solution using a script. The code follows the same process as the formula shown in the question.
SPLIT
, if there's a comma then we switch the names around; if not, we just use the name as-is,This screenshot shows the output: