EvangeliusAg
EvangeliusAg

Reputation: 159

Split arbitrary number of words into two columns - Google Sheets

tl;dr

How can I split an arbitrary number of words into only two columns, always with just the last word in the last column and all other words in the first column?

=IFS(
LEN(C2)-LEN(SUBSTITUTE(C2," ",""))=1,
 SPLIT(C2," "),
LEN(C2)-LEN(SUBSTITUTE(C2," ",""))=2,
 SPLIT(SUBSTITUTE(C2," ","%",2),"%"))
LEN(C2)-LEN(SUBSTITUTE(C2," ",""))=3,
 SPLIT(SUBSTITUTE(C2," ","%",3),"%"))   
)

Och, aye, laddies! I'm in a wee spare bit o' bother, an' I need yer help. I've ta take the mottos o' ALL the Scots clans, and t' break 'em oot inta columns in this parcel of codes called Google Sheets. Tak ye a few examples:

HOWEVER, for some daft reason, I've to put them into NAE MORE than two columns, with the last word comin' alone in the last column.

I've tried everythin' I cae think on - QUERY, LEN, SUBSTITUTE, SPLIT, SPIT, naught seems t' work. The code above will pull out the first word(s) in the first column all right an' tight, but it will nae expand as SPLIT is wont t' do.

I'm sure there's a barrel o' answers for R and what have ye...but how do ye do this in Google Sheets (aye, I need her in Sheets)?

Upvotes: 3

Views: 134

Answers (2)

TheMaster
TheMaster

Reputation: 50383

=SPLIT(SUBSTITUTE(A1," ","🧟",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))),"🧟")

Upvotes: 3

TheMaster
TheMaster

Reputation: 50383

=REGEXEXTRACT(A1,"(.*?) {0,1}(\w+)$")

Upvotes: 5

Related Questions