TEXTSPLIT splits an array of text values by a specified delimiter (like text to columns, or vba split function), allowing the user to select Nth split occurrence(s)
Excel Formula:
=LAMBDA(textToSplit,separator,nthOccurrence,
LET(tToS,textToSplit,
hrzntl,(ROWS(tToS)=1)*(COLUMNS(tToS)>1),
t,IF(hrzntl=1,TRANSPOSE(tToS),tToS),
r,ROWS(t),
s,separator,
seqR,SEQUENCE(r),
tLn,LEN(t),
sLn,LEN(s),
maxTLn,MAX(tLn),
noOfFinds,(tLn-LEN(SUBSTITUTE(t,s,"")))/sLn,maxF,MAX(noOfFinds),
seqT,SEQUENCE(,maxTLn),
finds,IF(seqT>tLn,0,seqT*(MID(t,seqT,sLn)=s)),
cntFinds,COUNTA(finds),
seqFinds,SEQUENCE(cntFinds,1,0),
rF,INT(seqFinds/maxTLn)+1,
finds_1d,INDEX(finds,rF,MOD(seqFinds,maxTLn)+1),
finds_1dSrt,SORTBY(finds_1d,rF&TEXT(IF(finds_1d=0,maxTLn+1,finds_1d),"0000000")),
finds_2d,INDEX(finds_1dSrt,maxTLn*(seqR-1)+SEQUENCE(,maxTLn),1),
seqN,SEQUENCE(,maxF+1,0),
starts,IF(seqN=0,1,INDEX(finds_2d,seqR,seqN)),
startPos,IF(starts<2,starts,starts+sLn),
ends,IF(seqN=noOfFinds,tLn+1,INDEX(finds_2d,seqR,seqN+1)),
splitArray,IF(startPos=0,"",MID(t,startPos,ends-startPos)),
nthCols,COLUMNS(nthOccurrence),
nC,IF(nthCols=1,IF(nthOccurrence=0,maxF+1,1),nthCols),
splitNth,IF(nthOccurrence=0,splitArray,INDEX(splitArray,seqR,nthOccurrence)),
indexNth,INDEX(splitNth,seqR,SEQUENCE(,nC)),
return,IF(hrzntl=1,TRANSPOSE(indexNth),indexNth),
return
)
)
Lambda - Last Cell and Split.xlsx | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
B | C | D | E | F | G | H | I | |||
2 | Split function, tested on horizontal array | Split function, tested on vertical array | ||||||||
3 | ||||||||||
4 | test;|of;|split;|this;|test | texas;|of;|split | treat;|me;|with;|care;|please;|people | test;|of;|split;|this;|test | |of | |split | |this | |||
5 | test | texas | treat | text;|of;|split | |of | |split | ||||
6 | of | of | me | teat;|of;|split;make;this;final;; | |of | |split | make | |||
7 | split | split | with | tent;|of;|split | |of | |split | ||||
8 | this | care | telt;|of;|split | |of | |split | |||||
9 | test | please | teft;|of;|split | |of | |split | |||||
10 | people | tert;|of;|split | |of | |split | ||||||
11 | teit;|of;|split | |of | |split | |||||||
12 | ||||||||||
Sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
G4:I11 | G4 | =TEXTSPLIT(F4:F11,";",{2,3,4}) |
B5:D10 | B5 | =TEXTSPLIT(B4:D4,";|",0) |
Dynamic array formulas. |
Last edited by a moderator:
Upvote
0