top of page

Excel Arena

This is the place, where we can test the boundaries of Excel functions.

Unleashing the Power of Excel Function - TEXT: A Formula Masterclass

Updated: Jun 3, 2024

Today's blog post is an enhanced version of our previous one.


The requirement is to extract numbers from an alphanumeric string in a manner that is both efficient and easy to comprehend. This solution is sure to impress with its simplicity and effectiveness. Lot to learn, let's dive in.


ree

The old formula is presented below.

=SUM(MID(0&B3,LARGE(ISNUMBER(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1)*1)*ROW(INDIRECT("1:"&LEN(B3)))+1,ROW(INDIRECT("1:"&LEN(B3)))),1)*(10^(ROW(INDIRECT("1:"&LEN(B3)))-1)))


ree

New Method:

The TEXT function allows us to accomplish the same task in a more efficient manner.

The TEXT function is essentially the formula approach to custom number formatting.

There are many ways to apply custom number formatting in a cell.

Basic format structure consists of four parts are shown below,


"Positive number; Negative number; Zero; Text"

Let me show you one simple example,

ree

Select cells C16:C19 and press Ctrl + 1 to apply custom number formatting,


ree

In Number tab, select the last option in category which is 'Custom' and enter

1;("Sorry");"Zero";"Name"

in type section and click OK.

ree

This alteration in format serves solely as an illustrative example.

The actual value in the cell remains unchanged; only its appearance is altered.


Any positive number within a specified range will display as 1.


Any negative number within the specified range will be displayed as (Sorry).


Any 0 within a specified range will display as zero.


Any text within a specified range will display as Name.


if we ignore any of the four parts, then particular part will be shown as blank.

;("Sorry");"Zero";"Name"

ree

We are going to use this type of format in TEXT function to do our task.

Formula in D3 cell is,

=CONCAT(TEXT(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1),"0;;;"))


Let me start this from scratch,

Inner core of this function is

ROW(INDIRECT("1:"&LEN(B3)))

This will create sequence of numbers from 1 to length of B3 cell value which is 20,

ree

Output of ROW, INDIRECT construction will look like below,

ree

MID function helps us to pick the substring of main text,

Start_num argument helps us to feed the starting position of substring,

num_chars argument helps to feed the length of substring.

MID function extracts one character from each starting position of 1,2,3 and so on.

So, output of MID function looks like below,

ree

In format text argument of TEXT function,

we feed four parts of format as we discussed earlier,

"0;;;"

We can use 0 or # symbol to show the positive number as it is in cell, we ignored remaining three parts. So, all parts other than positive numbers, will be shown as blanks.

ree

Concatenating these texts will yield the following output:

ree

Bonus Tip:

Below formula helps us to extract text from alphanumeric string,

=CONCAT(TEXT(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1),";;;@"))

"@" symbol in text format portion helps us to keep the text as it is in cell.

Ignore all other three parts to ignore anything other than text.

ree

The output following concatenation will appear as below,

ree

2 Comments


Rick Rothstein
Rick Rothstein
Jun 18, 2024

As written, your formula will not return zeros contained within the text. For example, your formula returns 12 for something like ab1cd000ef000gh2. You need to include a 0 in the zero position of the format pattern in order for the formula to return 0's...

=CONCAT(TEXT(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1),"0;;0;"))

Like
V E Meganathan
Jun 19, 2024
Replying to

Sure Rick, your point is taken.

Will improve to consider various aspects when we put content.

Like
  • LinkedIn
  • Facebook
  • Twitter
  • Instagram
bottom of page