XTRACT

=XTRACT(text,boolean)

text
a string value
[num_or_text]
optional argument. Nothing or 0 returns numbers, 1 returns text.

Extract either letters or numbers from a given string

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
3,963
Office Version
  1. 365
Platform
  1. Windows
XTRACT returns either letters or numbers from a given string.

There are different and maybe better or more concise ways to extract letters or numbers from a string. I just thought this was kind of a clever solution and cool that it lets you flip between returning numbers or letters.

Excel Formula:
=LAMBDA(
    text,[num_or_text],
    TAKE(
        SCAN(
            text,
            SEQUENCE(LEN(text)),
            LAMBDA(
                a,b,
                RIGHT(a,LEN(a)-1)
                &IF(
                    XOR(
                        ISNUMBER(LEFT(a)+0),
                        num_or_text
                    )
                    ,LEFT(a),
                    ""
                )
            )
        ),
        -1
    )
)

XTRACT
ABC
1ABC123123ABC
2456DEF456DEF
31a2b3c123abc
4x7y8z9789xyz
Sheet6
Cell Formulas
RangeFormula
B1:B4B1=XTRACT($A1)
C1:C4C1=XTRACT($A1,1)
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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