ATEXTSPLIT

=ATEXTSPLIT(ar,dl,ea)

ar
array strings, 1D vertical
dl
string, one or more characters
ea
0 or 1, 0 or omitted ignores empty ; 1 does not ignore empty

array text split by any delimiter,(one or more chars), fine-tuned for complex scenarios

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ATEXTSPLIT array text split by any delimiter,(one or more chars), fine-tuned for complex scenarios.
Wrote this function inspired by MrExcel video: Excel TEXTJOIN And The Need For TEXTSPLIT with Ann K. Emery - 2407
The idea was to create a function that is clean and robust, does not call other functions, non-recursive, no FILTERXML, and uses same arguments as TEXTJOIN. What TEXTJOIN joins, ATEXTSPLIT should be able to split it back like it was, with same arguments. When we join, we choose the delimiter, but when we split imported data, things can go quite tricky.
ar: array 1D vertical, dl: delimiter, any string , ea: empty argument , 0 or omitted - ignores empty ; 1 - does not ignore empty
Note: There are 2 special characters in the formula, (h,"º",d,"ª"), first variables after "LET" . These should be changed if any of them is found on the array of strings. Formula advises if this happens.
Excel Formula:
=LAMBDA(ar,dl,ea,
    LET(h,"º",d,"ª",ch,ISNUMBER(SEARCH(CHOOSE({1,2},h,d),ar)),
       a,SUBSTITUTE(ar,dl,d),b,IF(ea,a,SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(a," ",h),d," "))," ",d),h," ")),
       n,LEN(b)-LEN(SUBSTITUTE(b,d,""))+1,c,MAX(n),sc,SEQUENCE(,c),
       x,SEARCH(h,SUBSTITUTE(d&b,d,h,sc)),y,SEARCH(h,SUBSTITUTE(b&d,d,h,sc)),m,IFERROR(MID(b,x,y-x),""),
       IF(OR(ch),"change special chars",IFERROR(--m,m))
    )
)
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
1TEXTJOINATEXTSPLIT
2empty ignoredempty not ignored2 charsempty ignored
3empty not ignoredea arg.=0ea arg.=1delimiterea arg.=0
4sample=TEXTJOIN(",",0,A5:D5)=ATEXTSPLIT(F5:F7,",",)=ATEXTSPLIT(F5:F7,",",1)=ATEXTSPLIT(T5:T7,"><",)LEN check
5a4ca,4,,ca4ca4ca><6.8><ta6.8t131
6d0.5d,,,0.5d0.5d0.5><2.4 w><2.4 w600
7g hi 2k l3 ng h,i 2,k l,3 ng hi 2k l3 ng hi 2k l3 n<Ac4><gh>< ><<Ac4gh 421
8space
9empty ignoredea arg.=0ea arg.=1empty not ignored
10=TEXTJOIN(",",,A5:D5)=ATEXTSPLIT(F11:F13,",",)=ATEXTSPLIT(F11:F13,",",1)ea arg.=1
11a,4,ca4ca4c=ATEXTSPLIT(T5:T7,"><",1)LEN check
12d,0.5d0.5d0.5a6.8t1310
13g h,i 2,k l,3 ng hi 2k l3 ng hi 2k l3 n2.4 w0600
14<Ac4gh 4210
15Complex scenariospace followed by an empty string
16empty ignoredempty not ignored
17ea arg.=0ea arg.=1error debug.
18sample=ATEXTSPLIT(F19:F22,",",)=ATEXTSPLIT(F19:F22,",",1)=ATEXTSPLIT(X19,",",)
19a,b,c,2.3,,d e,abc2.3d eabc2.3d ea,ºb,cchange special chars
20,,g,,h, ,1.8gh 1.8gh 1.8=ATEXTSPLIT(X21,",",1)
21, k m, ,4.9, ,p k m 4.9 p k m 4.9 pa,ªb,cchange special chars
22, ,,x 4, ,, x 4 x 4
23
24Important Obs.: -two delimiters next to each other ( ,, ) , hold an empty string between them that can be ignored or not depending of "ea" argument
25 -two delimiters sep by space ( , , ) , hold a space between them, and can not be ignored, no matter of "ea" argument
26 We can check this behaviour with LEN function. (same rule applies for leading or trailing delimiters)
27
28=LEN(H19#)=LEN(N19#)
29111331113030
30111300010113
31413110413110
32151000105100
33
34- if values themselves embed inner spaces, could be important to keep them (like special codes with fixed length that follow a pattern),TRIM tweaks can not be used
35
36ex. code patternsample=ATEXTSPLIT(F37:F38,"/",)=LEN(H37#)
37fixed with 4 pos.a bc/a b/ bcda bca b bcd444
38/____ /ab d/ d/a ab d da 444
39/xxxx/check:pattern is kept
40
ATEXTSPLIT post
Cell Formulas
RangeFormula
H4,N36,H36,N28,H28,Z18,Z20,N18,H18,F10,X11,N10,H10,F4,X4,N4H4=FORMULATEXT(H5)
H5:K7,H11:K13H5=ATEXTSPLIT(F5:F7,",",)
N5:Q7,N11:Q13N5=ATEXTSPLIT(F5:F7,",",1)
X5:Z7X5=ATEXTSPLIT(T5:T7,"><",)
AC5:AE7,AC12:AF14AC5=LEN(X5#)
F5:F7F5=TEXTJOIN(",",0,A5:D5)
X12:AA14X12=ATEXTSPLIT(T5:T7,"><",1)
F11:F13F11=TEXTJOIN(",",,A5:D5)
H19:L22H19=ATEXTSPLIT(F19:F22,",",)
N19:T22N19=ATEXTSPLIT(F19:F22,",",1)
Z19Z19=ATEXTSPLIT(X19,",",)
Z21Z21=ATEXTSPLIT(X21,",",1)
H29:L32,N29:T32H29=LEN(H19#)
H37:J38H37=ATEXTSPLIT(F37:F38,"/",)
N37:P38N37=LEN(H37#)
Dynamic array formulas.
 
Upvote 0
3rd module: SN(a) Spelling Numbers
a: single value, positive integer up to 15 digits ( <1E+16, one quadrillion)
Excel Formula:
=LAMBDA(c, [nd],
    LET(
        k, INDEX(DE(), 11, ),
        a, INT(ABS(c)),
        n, IF(LEN(a) > 15, 0, a),
        t, TEXT(n, REPT(0, 15)),
        m, MID(t, SEQUENCE(, 5, , 3), 3),
        h, SH(m),
        x, TEXTJOIN("", , h & IF(h = "", "", k)),
        r, LEFT(TEXTAFTER(c, ".", , , , 0), 2),
        d, IF(LEN(r) = 1, r & 0, r),
        y, SH(d),
        IF(nd, y, x)
    )
)
SPLNRS.xlsx
ABCDEFGH
1pattern formulas to
2replace typing
3=REPT(9,SEQUENCE(16,,16,-1))=E4#&""=--B4#
4999999999999999999999999999999901E+16 =SN(E4)
59999999999999999999999999999991E+15nine hundred ninety nine trillion nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E5)
699999999999999999999999999991E+14ninety nine trillion nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E6)
7999999999999999999999999991E+13nine trillion nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E7)
89999999999999999999999991E+12nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E8)
9999999999999999999999999999999999ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E9)
10999999999999999999999999999999nine billion nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E10)
11999999999999999999999999999nine hundred ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E11)
12999999999999999999999999ninety nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E12)
13999999999999999999999nine million nine hundred ninety nine thousands nine hundred ninety nine=SN(E13)
14999999999999999999nine hundred ninety nine thousands nine hundred ninety nine=SN(E14)
15999999999999999ninety nine thousands nine hundred ninety nine=SN(E15)
16999999999999nine thousands nine hundred ninety nine=SN(E16)
17999999999nine hundred ninety nine=SN(E17)
18999999ninety nine=SN(E18)
19999nine=SN(E19)
20
21=1&REPT(0,SEQUENCE(15)-1)&1=E22#&""=--B22#
22111111eleven=SN(E22)
23101101101one hundred one=SN(E23)
24100110011001one thousands one=SN(E24)
25100011000110001ten thousands one=SN(E25)
26100001100001100001one hundred thousands one=SN(E26)
27100000110000011000001one million one=SN(E27)
28100000011000000110000001ten million one=SN(E28)
29100000001100000001100000001one hundred million one=SN(E29)
30100000000110000000011000000001one billion one=SN(E30)
31100000000011000000000110000000001ten billion one=SN(E31)
321000000000011000000000011E+11one hundred billion one=SN(E32)
33100000000000110000000000011E+12one trillion one=SN(E33)
3410000000000001100000000000011E+13ten trillion one=SN(E34)
351000000000000011000000000000011E+14one hundred trillion one=SN(E35)
36100000000000000110000000000000001E+15 =SN(E36)
37
38
39 - after 15 digits numbers we loose precision (last digit is 0 even if we used 9 and 1) => SN returns empty string ""
40
SN
Cell Formulas
RangeFormula
B3,D21:E21,B21,D3:E3B3=FORMULATEXT(B4)
D4:D19,D22:D36D4=E4#&""
E4:E19,E22:E36E4=--B4#
B4:B19B4=REPT(9,SEQUENCE(16,,16,-1))
F4:F19,F22:F36F4=SN(E4)
G4:G19,G22:G36G4=FORMULATEXT(F4)
B22:B36B22=1&REPT(0,SEQUENCE(15)-1)&1
Dynamic array formulas.
 
Forgot to mention the new functionality added by second argument "nd". Actually, SN function can handle positive decimal numbers, rounding them to 2 digits.
SN(c,[nd]) Spell Numbers. Calls SH(a)
c: single value/cell, positive decimal numbers < 1 quadrillion
[nd]: number's decimals argument
- if nd omitted, only INT part of the number is spelled
- if nd 1 or <>0, only number's decimals are spelled
SPLNRS.xlsx
ABCDEFGHI
1=RANDARRAY(40,,1,100000)nd, omitted => spelling INT partnd, 1 => spelling decimals
2↓↓↓
397702.56825ninety seven thousands seven hundred two=SN(B3)fifty six=SN(B3,1)
420409.42607twenty thousands four hundred nine=SN(B4)forty two=SN(B4,1)
520746.85651twenty thousands seven hundred forty six=SN(B5)eighty five=SN(B5,1)
626932.53347twenty six thousands nine hundred thirty two=SN(B6)fifty three=SN(B6,1)
742940.80901forty two thousands nine hundred forty=SN(B7)eighty=SN(B7,1)
830311.15541thirty thousands three hundred eleven=SN(B8)fifteen=SN(B8,1)
96505.022883six thousands five hundred five=SN(B9)two=SN(B9,1)
1072210.82081seventy two thousands two hundred ten=SN(B10)eighty two=SN(B10,1)
1177101.23987seventy seven thousands one hundred one=SN(B11)twenty three=SN(B11,1)
123902.495388three thousands nine hundred two=SN(B12)forty nine=SN(B12,1)
1375828.70297seventy five thousands eight hundred twenty eight=SN(B13)seventy=SN(B13,1)
1482240.43437eighty two thousands two hundred forty=SN(B14)forty three=SN(B14,1)
1532232.28521thirty two thousands two hundred thirty two=SN(B15)twenty eight=SN(B15,1)
1687495.94881eighty seven thousands four hundred ninety five=SN(B16)ninety four=SN(B16,1)
1764026.98905sixty four thousands twenty six=SN(B17)ninety eight=SN(B17,1)
188524.822263eight thousands five hundred twenty four=SN(B18)eighty two=SN(B18,1)
191354.381408one thousands three hundred fifty four=SN(B19)thirty eight=SN(B19,1)
2073236.2476seventy three thousands two hundred thirty six=SN(B20)twenty four=SN(B20,1)
2180278.38307eighty thousands two hundred seventy eight=SN(B21)thirty eight=SN(B21,1)
2211755.34121eleven thousands seven hundred fifty five=SN(B22)thirty four=SN(B22,1)
2368140.79487sixty eight thousands one hundred forty=SN(B23)seventy nine=SN(B23,1)
2483420.25187eighty three thousands four hundred twenty=SN(B24)twenty five=SN(B24,1)
2546341.57505forty six thousands three hundred forty one=SN(B25)fifty seven=SN(B25,1)
2683785.53183eighty three thousands seven hundred eighty five=SN(B26)fifty three=SN(B26,1)
2788819.41514eighty eight thousands eight hundred nineteen=SN(B27)forty one=SN(B27,1)
2831223.40664thirty one thousands two hundred twenty three=SN(B28)forty=SN(B28,1)
2958748.10724fifty eight thousands seven hundred forty eight=SN(B29)ten=SN(B29,1)
301259.293816one thousands two hundred fifty nine=SN(B30)twenty nine=SN(B30,1)
3115428.78558fifteen thousands four hundred twenty eight=SN(B31)seventy eight=SN(B31,1)
329053.159079nine thousands fifty three=SN(B32)fifteen=SN(B32,1)
3381874.28178eighty one thousands eight hundred seventy four=SN(B33)twenty eight=SN(B33,1)
3439330.87146thirty nine thousands three hundred thirty=SN(B34)eighty seven=SN(B34,1)
3576535.69963seventy six thousands five hundred thirty five=SN(B35)sixty nine=SN(B35,1)
3668282.01577sixty eight thousands two hundred eighty two=SN(B36)one=SN(B36,1)
372218.17782two thousands two hundred eighteen=SN(B37)seventeen=SN(B37,1)
3813299.91768thirteen thousands two hundred ninety nine=SN(B38)ninety one=SN(B38,1)
3959174.64585fifty nine thousands one hundred seventy four=SN(B39)sixty four=SN(B39,1)
4087416.30462eighty seven thousands four hundred sixteen=SN(B40)thirty=SN(B40,1)
4121197.93743twenty one thousands one hundred ninety seven=SN(B41)ninety three=SN(B41,1)
4280459.41039eighty thousands four hundred fifty nine=SN(B42)forty one=SN(B42,1)
43
Sheet3
Cell Formulas
RangeFormula
B1B1=FORMULATEXT(B3)
B3:B42B3=RANDARRAY(40,,1,100000)
D3:D42D3=SN(B3)
E3:E42,H3:H42E3=FORMULATEXT(D3)
G3:G42G3=SN(B3,1)
Dynamic array formulas.
 
4th module: SPLNRS(ar,[un])
Main function that assembles all the other modules relationships and does the rest of cosmetics. Calls SN that calls SH that calls DE.
To keep it unclustered of too many arguments for unit selection, chose a plain design that defines default unit to be used inside the function's expression, since will not be changed so often.
ar: any array of positive or negative decimal numbers
- if ar contains text, errors, blanks/empty strings, or numbers that in absolute value are greater than 1 quadrillion -1, the function will ignore them, returning empty strings instead.
[un]: unit argument
- if omitted or 0, default unit's names spelling will be added
The default unit in our case: " Dollars"/" Cents" can be changed inside the function's expression, together with "negative " and " and " words if different translation is needed.
- if 1 or <>0, no unit's name spelling will be added.
Excel Formula:
=LAMBDA(ar, [un],
    LET(
        u, IF(un, "", " Dollars"),
        h, IF(un, INDEX(DE(), 2, 5), " Cents"),
        g, "negative ",
        p, " and ",
        MAP(
            ar,
            LAMBDA(a,
                LET(
                    n, SN(a),
                    d, SN(a, 1),
                    x, IF(
                        n = "",
                        IF(d = "", "", d & h),
                        IF(d = "", n & u, n & u & p & d & h)
                    ),
                    IFERROR(IF(a < 0, g & x, x), "")
                )
            )
        )
    )
)
SPLNRS.xlsx
ABCDEFGHI
1=RANDARRAY(20,,-1000000000,1000000000)-1<=ar<=1
2↓↓↓un, omitted=RANDARRAY(20,,-1,1)
3↓↓↓=SPLNRS(B4#)↓↓↓=SPLNRS(F4#)
4ar-646420771.8negative six hundred forty six million four hundred twenty thousands seven hundred seventy one Dollars and eighty three Centsar0.393619238thirty nine Cents
5-306021547.1negative three hundred six million twenty one thousands five hundred forty seven Dollars and eleven Cents-0.6058294negative sixty Cents
6-245872533.4negative two hundred forty five million eight hundred seventy two thousands five hundred thirty three Dollars and forty Cents-0.12291204negative twelve Cents
7754545146seven hundred fifty four million five hundred forty five thousands one hundred forty six Dollars-0.75428247negative seventy five Cents
8583090548.3five hundred eighty three million ninety thousands five hundred forty eight Dollars and thirty two Cents0.463274936forty six Cents
9972446830.9nine hundred seventy two million four hundred forty six thousands eight hundred thirty Dollars and ninety four Cents0.519382307fifty one Cents
10254700856.8two hundred fifty four million seven hundred thousands eight hundred fifty six Dollars and seventy nine Cents-0.54502695negative fifty four Cents
11237225830.4two hundred thirty seven million two hundred twenty five thousands eight hundred thirty Dollars and thirty seven Cents0.54524941fifty four Cents
12-803488160.8negative eight hundred three million four hundred eighty eight thousands one hundred sixty Dollars and eighty Cents0.543190105fifty four Cents
13-771685306.8negative seven hundred seventy one million six hundred eighty five thousands three hundred six Dollars and eighty four Cents-0.46412196negative forty six Cents
14441633269.8four hundred forty one million six hundred thirty three thousands two hundred sixty nine Dollars and seventy six Cents-0.07641586negative seven Cents
15-869418398.2negative eight hundred sixty nine million four hundred eighteen thousands three hundred ninety eight Dollars and twenty one Cents-0.25065356negative twenty five Cents
16631463792.4six hundred thirty one million four hundred sixty three thousands seven hundred ninety two Dollars and thirty five Cents0.272158829twenty seven Cents
17-157997948.2negative one hundred fifty seven million nine hundred ninety seven thousands nine hundred forty eight Dollars and twenty one Cents-0.8389929negative eighty three Cents
18-213953591.5negative two hundred thirteen million nine hundred fifty three thousands five hundred ninety one Dollars and fifty two Cents0.551709823fifty five Cents
19-208205080.7negative two hundred eight million two hundred five thousands eighty Dollars and sixty nine Cents-0.33794313negative thirty three Cents
20-31539376.39negative thirty one million five hundred thirty nine thousands three hundred seventy six Dollars and thirty eight Cents0.505204421fifty Cents
21-95437514.86negative ninety five million four hundred thirty seven thousands five hundred fourteen Dollars and eighty six Cents0.932753939ninety three Cents
22610791237.9six hundred ten million seven hundred ninety one thousands two hundred thirty seven Dollars and eighty six Cents0.417721416forty one Cents
23-409109942.8negative four hundred nine million one hundred nine thousands nine hundred forty two Dollars and eighty one Cents-0.20266916negative twenty Cents
24
25even if excel displays
26only 1 digit decimals,
27more of them are hiddenun,1
28=B4#&""=SPLNRS(B4#,1)=SPLNRS(F4#,1)
29-646420771.831535negative six hundred forty six million four hundred twenty thousands seven hundred seventy one and eighty three hundredth thirty nine hundredth
30-306021547.110803negative three hundred six million twenty one thousands five hundred forty seven and eleven hundredth negative sixty hundredth
31-245872533.406896negative two hundred forty five million eight hundred seventy two thousands five hundred thirty three and forty hundredth negative twelve hundredth
32754545146.000781seven hundred fifty four million five hundred forty five thousands one hundred forty sixnegative seventy five hundredth
33583090548.323593five hundred eighty three million ninety thousands five hundred forty eight and thirty two hundredth forty six hundredth
34972446830.947536nine hundred seventy two million four hundred forty six thousands eight hundred thirty and ninety four hundredth fifty one hundredth
35254700856.799245two hundred fifty four million seven hundred thousands eight hundred fifty six and seventy nine hundredth negative fifty four hundredth
36237225830.370408two hundred thirty seven million two hundred twenty five thousands eight hundred thirty and thirty seven hundredth fifty four hundredth
37-803488160.807744negative eight hundred three million four hundred eighty eight thousands one hundred sixty and eighty hundredth fifty four hundredth
38-771685306.846232negative seven hundred seventy one million six hundred eighty five thousands three hundred six and eighty four hundredth negative forty six hundredth
39441633269.766593four hundred forty one million six hundred thirty three thousands two hundred sixty nine and seventy six hundredth negative seven hundredth
40-869418398.215256negative eight hundred sixty nine million four hundred eighteen thousands three hundred ninety eight and twenty one hundredth negative twenty five hundredth
41631463792.356621six hundred thirty one million four hundred sixty three thousands seven hundred ninety two and thirty five hundredth twenty seven hundredth
42-157997948.212424negative one hundred fifty seven million nine hundred ninety seven thousands nine hundred forty eight and twenty one hundredth negative eighty three hundredth
43-213953591.525161negative two hundred thirteen million nine hundred fifty three thousands five hundred ninety one and fifty two hundredth fifty five hundredth
44-208205080.696565negative two hundred eight million two hundred five thousands eighty and sixty nine hundredth negative thirty three hundredth
45-31539376.3871949negative thirty one million five hundred thirty nine thousands three hundred seventy six and thirty eight hundredth fifty hundredth
46-95437514.8631116negative ninety five million four hundred thirty seven thousands five hundred fourteen and eighty six hundredth ninety three hundredth
47610791237.864715six hundred ten million seven hundred ninety one thousands two hundred thirty seven and eighty six hundredth forty one hundredth
48-409109942.819211negative four hundred nine million one hundred nine thousands nine hundred forty two and eighty one hundredth negative twenty hundredth
49
SPLNRS
Cell Formulas
RangeFormula
B1B1=FORMULATEXT(B4)
F2F2=FORMULATEXT(F4)
B4:B23B4=RANDARRAY(20,,-1000000000,1000000000)
D3,H28,D28,B28,H3D3=FORMULATEXT(D4)
D4:D23,H4:H23D4=SPLNRS(B4#)
F4:F23F4=RANDARRAY(20,,-1,1)
B29:B48B29=B4#&""
D29:D48,H29:H48D29=SPLNRS(B4#,1)
Dynamic array formulas.
 
SPLNRS.xlsx
ABCDEFGHI
1data types managementun,1
2"ar" 2D =SPLNRS(B3:D5,1)
35432.68-456.725#N/Afive thousands four hundred thirty two and sixty eight hundredth negative four hundred fifty six and seventy two hundredth
4text-37567.19-101001negative thirty seven thousands five hundred sixty seven and nineteen hundredth negative one hundred one thousands one
59.87988E+1510101010ten million one hundred one thousands ten
6
7un, omitted
8=SPLNRS(B3:D5)
9five thousands four hundred thirty two Dollars and sixty eight Centsnegative four hundred fifty six Dollars and seventy two Cents
10negative thirty seven thousands five hundred sixty seven Dollars and nineteen Centsnegative one hundred one thousands one Dollars
11ten million one hundred one thousands ten Dollars
12
13
SPLNRS 1
Cell Formulas
RangeFormula
D3D3=NA()
F2,F8F2=FORMULATEXT(F3)
F3:H5F3=SPLNRS(B3:D5,1)
F9:H11F9=SPLNRS(B3:D5)
Dynamic array formulas.
 
It seems like you could just use textbefore/after for this.
You are right @jaeiow. Here is a function that uses both TEXTBEFORE, TEXTAFTER, and not only for spaces, for any characters.
TRIMENDS(t,ch,[lt]) Trim leading, trailing characters, or both. All other chars are left intact.
t: text, single cell/value
ch: character
[lt]: leading, trailing argument: 0 or omitted=>remove all leading "ch" ; if 1, trailing "ch" ; if 2, both leading and trailing
Excel Formula:
=LAMBDA(t, ch, [lt],
    LET(
        n, LEN(t),
        s, SUBSTITUTE(t, ch, ""),
        l, LEFT(s, 1),
        r, RIGHT(s, 1),
        x, LEN(TEXTBEFORE(t, l)),
        y, LEN(TEXTAFTER(t, r, -1)),
        SWITCH(lt, 0, RIGHT(t, n - x), 1, LEFT(t, n - y), 2, MID(t, x + 1, n - x - y))
    )
)
ATRIM new.xlsx
ABCDEFGHIJK
1
2tch,"x", lt, omitted
3xxxxjyhgu xxxx-uoygxx xxxouytoyu ytfytfxxxxxx=TRIMENDS(B3,"x")
4jyhgu xxxx-uoygxx xxxouytoyu ytfytfxxxxxx
5
6ch,"x",lt,1
7=TRIMENDS(B3,"x",1)
8xxxxjyhgu xxxx-uoygxx xxxouytoyu ytfytf
9
10ch,"x", lt,2
11=TRIMENDS(B3,"x",2)
12jyhgu xxxx-uoygxx xxxouytoyu ytfytf
13
14Trim both ends of an array of strings for "x"
15array=MAP(B16:B17,LAMBDA(x,TRIMENDS(x,"x",2)))
16xxxxjyhgu xxxx-uoygxx xxxouytoyu ytfytfxxxxxxjyhgu xxxx-uoygxx xxxouytoyu ytfytf
17xxbb-jbi-xxx (lkjh8976) 1234xxxxxxxxxbb-jbi-xxx (lkjh8976) 1234
18
19Trim array acording to first chars (variable, leading=trailing)
20=LEFT(B22:B23,1)
21array↓↓=MAP(B22:B23,D22#,LAMBDA(x,y,TRIMENDS(x,y,2)))
22yyiughi-yuguyutyyyyyyyiughi-yuguyut
23zzzzzzzzzzzziugug 9876987zzzzzziugug 9876987
24
25Trim array, variable chars, leading<>trailing, single cell formula
26
27array=MAP(B28:B29,LEFT(B28:B29,1),RIGHT(B28:B29,1),LAMBDA(x,y,z,TRIMENDS(TRIMENDS(x,y),z,1)))
28yyyljhgl765 ugugu976987wwwwwljhgl765 ugugu976987
29xxxxx7865jhgj jhgjhg8765zzzzzzzzzzzz7865jhgj jhgjhg8765
30
trim ends
Cell Formulas
RangeFormula
G3,G21,G15,G11,G7G3=FORMULATEXT(G4)
G4G4=TRIMENDS(B3,"x")
G8G8=TRIMENDS(B3,"x",1)
G12G12=TRIMENDS(B3,"x",2)
G16:G17G16=MAP(B16:B17,LAMBDA(x,TRIMENDS(x,"x",2)))
D20D20=FORMULATEXT(D22)
D22:D23D22=LEFT(B22:B23,1)
G22:G23G22=MAP(B22:B23,D22#,LAMBDA(x,y,TRIMENDS(x,y,2)))
D27D27=FORMULATEXT(G28)
G28:G29G28=MAP(B28:B29,LEFT(B28:B29,1),RIGHT(B28:B29,1),LAMBDA(x,y,z,TRIMENDS(TRIMENDS(x,y),z,1)))
Dynamic array formulas.
 
Fun Challenge inspired from latest YT of @MrExcel
REGEX is best formula to solve what the video says: Extract everything after first digit and this coincides with extracting addresses for this specific format.
Challenge: What if the records have more numbers, how we can extract only the correct address?
hypothesis: An address starts with a number and finishes with a number. The word before last number should be a US state.
Asked copilot to deliver all US states in a tabular form
Book1
ABCDEF
1StateAbbreviationCapital=us
2AlabamaALMontgomeryAlabama
3AlaskaAKJuneauAlaska
4ArizonaAZPhoenixArizona
5ArkansasARLittle RockArkansas
6CaliforniaCASacramentoCalifornia
7ColoradoCODenverColorado
8ConnecticutCTHartfordConnecticut
9DelawareDEDoverDelaware
10FloridaFLTallahasseeFlorida
11GeorgiaGAAtlantaGeorgia
12HawaiiHIHonoluluHawaii
13IdahoIDBoiseIdaho
14IllinoisILSpringfieldIllinois
15IndianaINIndianapolisIndiana
16IowaIADes MoinesIowa
17KansasKSTopekaKansas
18KentuckyKYFrankfortKentucky
19LouisianaLABaton RougeLouisiana
20MaineMEAugustaMaine
21MarylandMDAnnapolisMaryland
22MassachusettsMABostonMassachusetts
23MichiganMILansingMichigan
24MinnesotaMNSaint PaulMinnesota
25MississippiMSJacksonMississippi
26MissouriMOJefferson CityMissouri
27MontanaMTHelenaMontana
28NebraskaNELincolnNebraska
29NevadaNVCarson CityNevada
30New HampshireNHConcordNew Hampshire
31New JerseyNJTrentonNew Jersey
32New MexicoNMSanta FeNew Mexico
33New YorkNYAlbanyNew York
34North CarolinaNCRaleighNorth Carolina
35North DakotaNDBismarckNorth Dakota
36OhioOHColumbusOhio
37OklahomaOKOklahoma CityOklahoma
38OregonORSalemOregon
39PennsylvaniaPAHarrisburgPennsylvania
40Rhode IslandRIProvidenceRhode Island
41South CarolinaSCColumbiaSouth Carolina
42South DakotaSDPierreSouth Dakota
43TennesseeTNNashvilleTennessee
44TexasTXAustinTexas
45UtahUTSalt Lake CityUtah
46VermontVTMontpelierVermont
47VirginiaVARichmondVirginia
48WashingtonWAOlympiaWashington
49West VirginiaWVCharlestonWest Virginia
50WisconsinWIMadisonWisconsin
51WyomingWYCheyenneWyoming
52
Sheet1
Cell Formulas
RangeFormula
E1E1=FORMULATEXT(E2)
E2:E51E2=us
Dynamic array formulas.


defined name: us
Excel Formula:
={"Alabama";"Alaska";"Arizona";"Arkansas";"California";"Colorado";"Connecticut";"Delaware";"Florida";"Georgia";"Hawaii";"Idaho";"Illinois";"Indiana";"Iowa";"Kansas";"Kentucky";"Louisiana";"Maine";"Maryland";"Massachusetts";"Michigan";"Minnesota";"Mississippi";"Missouri";"Montana";"Nebraska";"Nevada";"New Hampshire";"New Jersey";"New Mexico";"New York";"North Carolina";"North Dakota";"Ohio";"Oklahoma";"Oregon";"Pennsylvania";"Rhode Island";"South Carolina";"South Dakota";"Tennessee";"Texas";"Utah";"Vermont";"Virginia";"Washington";"West Virginia";"Wisconsin";"Wyoming"}

Concept step by step:
Book1
ABCDEFGHIJKLMNOPQRSTUVW
1Concept. Extract an address if more numbers / record
2
3123 abcd 456 re-attach gutter 421 Nut Ave NE Tampa Florida 83503 Florida state 25 Miami 83503
4
51.text split2. position of nr.3. positions before numbers4. extract only words before a nr.6. first nr. before state match
6
7=TEXTSPLIT(B3,," ")=--ISNUMBER(--B8#)=VSTACK(DROP(D8#,1),0)=IF(F8#,B8#)5. match text as US state=TAKE(D8#,M12)
812310FALSE1=XMATCH(1,O8#,,-1)
9abcd01abcd=IFNA(XMATCH(us,I8#),0)06
1045610FALSE01
11re-attach00FALSE0=FILTER(K10#,K10#)07. extract everything btw
12gutter01gutter0110first nr. before a state
1342110FALSE01and state position +1
14Nut00FALSE00
15Ave00FALSE00=INDEX(B8#,SEQUENCE(M12-Q9+2,,Q9))
16NE00FALSE00421
17Tampa00FALSE00Nut
18Florida01Florida110Ave
198350310FALSE0NE
20Florida00FALSE0Tampa
21state01state0Florida
222510FALSE083503
23Miami01Miami08. Final
248350310FALSE0
250=TEXTJOIN(" ",,Q16#)
260421 Nut Ave NE Tampa Florida 83503
270
280instead of
290
300=REGEXEXTRACT(B3,"\d.*")
310123 abcd 456 re-attach gutter 421 Nut Ave NE Tampa Florida 83503 Florida state 25 Miami 83503
320
330or
340
350=TEXTAFTER(B3,TEXTBEFORE(B3,SEQUENCE(10,,0)))
360123 abcd 456 re-attach gutter 421 Nut Ave NE Tampa Florida 83503 Florida state 25 Miami 83503
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
Sheet2
Cell Formulas
RangeFormula
B7,D7,F7,I7,N35,N30,N25,Q15,M11,K9,Q8,O7B7=FORMULATEXT(B8)
B8:B24B8=TEXTSPLIT(B3,," ")
D8:D24D8=--ISNUMBER(--B8#)
F8:F24F8=VSTACK(DROP(D8#,1),0)
I8:I24I8=IF(F8#,B8#)
O8:O18O8=TAKE(D8#,M12)
Q9Q9=XMATCH(1,O8#,,-1)
K10:K59K10=IFNA(XMATCH(us,I8#),0)
M12M12=FILTER(K10#,K10#)
Q16:Q22Q16=INDEX(B8#,SEQUENCE(M12-Q9+2,,Q9))
N26N26=TEXTJOIN(" ",,Q16#)
N31N31=REGEXEXTRACT(B3,"\d.*")
N36N36=TEXTAFTER(B3,TEXTBEFORE(B3,SEQUENCE(10,,0)))
Dynamic array formulas.


The function USA(a,[d]) US Address calls defined name: us
a: any array
d: delimiter, if omitted d=" "
Excel Formula:
=LAMBDA(a, [d],
    LET(
        e, IF(d = "", " ", d),
        f, LAMBDA(x,
            LET(
                t, TEXTSPLIT(x, , e),
                i, --ISNUMBER(--t),
                j, VSTACK(DROP(i, 1), 0),
                f, IF(j, t),
                m, IFNA(XMATCH(us, f), 0),
                l, INDEX(FILTER(m, m), 1),
                k, XMATCH(1, TAKE(i, l), , -1),
                TEXTJOIN(" ", , INDEX(t, SEQUENCE(l - k + 2, , k)))
            )
        ),
        IFERROR(MAP(a, f), "")
    )
)
Book1
ABCDE
1
2=USA(B3:B22)
3432 kg Polish brass 345 m rail 834 Rate Blvd Pearland Texas 74131 abc 12345 def 3456834 Rate Blvd Pearland Texas 74131
4tuck point bricks 5547 Nose Ln Austin Texas 370145547 Nose Ln Austin Texas 37014
5repair shingle 4488 Flame Boulevard SE Baltimore Maryland 949084488 Flame Boulevard SE Baltimore Maryland 94908
6123 abcd 456 re-attach gutter 421 Nut Ave NE Tampa Florida 83503 xyz 567 Miami 83503421 Nut Ave NE Tampa Florida 83503
7Paint fence 1968 Canvas Boulevard St. Petersburg Florida 910441968 Canvas Boulevard St. Petersburg Florida 91044
8General landscape maintenance 5768 Sofa Ln W Kent Washington 158595768 Sofa Ln W Kent Washington 15859
9Spray weeds 3579 Governor Lane Naperville Illinois 855383579 Governor Lane Naperville Illinois 85538
10Install porch light 969 Mouth St N Jackson Mississippi 51228969 Mouth St N Jackson Mississippi 51228
11replace bulb in security light 4183 Aunt Lane S Naperville Illinois 655774183 Aunt Lane S Naperville Illinois 65577
12mow the lawn 305 Calendar Street W Killeen Texas 72119305 Calendar Street W Killeen Texas 72119
13fix the tractor 8109 Note Ln Jackson Mississippi 688488109 Note Ln Jackson Mississippi 68848
14hang wall hanging 348 Minute St Savannah Georgia 18854348 Minute St Savannah Georgia 18854
15neon sign repair 8404 Star Blvd Arlington Texas 242658404 Star Blvd Arlington Texas 24265
16fixing leaky faucets 9479 Quarter Street S Oklahoma City Oklahoma 768239479 Quarter Street S Oklahoma City Oklahoma 76823
17repair drywall 9992 Prison Ln SW Pomona California 735379992 Prison Ln SW Pomona California 73537
18Assembling furniture 66 Knife Boulevard Overland Park Kansas 6523866 Knife Boulevard Overland Park Kansas 65238
19Painting front door 673 Furniture Boulevard Pearland Texas 84172673 Furniture Boulevard Pearland Texas 84172
20Replacing ceiling fan 7373 Loss Street N Orange California 827217373 Loss Street N Orange California 82721
21abcd 1234 tyughi 3456 uiho Miami 34567
22Installing shelves 1609 Crayon Blvd S Olathe Kansas 923451609 Crayon Blvd S Olathe Kansas 92345
23
Sheet3
Cell Formulas
RangeFormula
D2D2=FORMULATEXT(D3)
D3:D22D3=USA(B3:B22)
Dynamic array formulas.
 

Forum statistics

Threads
1,223,875
Messages
6,175,116
Members
452,613
Latest member
amorehouse

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top