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.
if else
statement I think: if a comma is present, the cell contains last then first name; otherwise the names are first followed by last. So far (I believe anyway), that's not my problem. My questions is really meant to focus on a way to essentially create a function that applies over many cells (each individually) in a loop...