Extracting numbers from a string 4: All numbers to a single cell 3

This is the fourth in a series of discussions on the techniques available for extracting numbers from an alphanumeric string.

In the first instalment in this series (which can be found here) I looked at extracting consecutive numbers which appear at the start of the string, e.g. 123ABC456.

In the second instalment (here) I looked at extracting consecutive numbers which appear at the end of the string, e.g. 123ABC456.

In the third instalment (here) I looked at extracting all numbers from a string where each of those numbers was to be returned to a separate cell. For example, given the string 81;8.75>@5279@4.=45>A?A; we extracted 81, 8.75, 5279, 4 and 45 into individual cells.

In this post I will look at a technique for extracting all numbers from a string, but where those numbers are to be returned as a single number in a single cell.

I will use the same string as in the previous post, i.e. 81;8.75>@5279@4.=45>A?A; though this time the desired resuilt will be:


Note that, due to the fact that Excel’s worksheet functions do not provide a native means by which we can pass arrays of strings to a concatenating function, the only viable means by which we will be able to arrive at our result will be to generate a proper numerical return.

As such, unless we repeat the method outlined over several iterations, and then concatenate the results, our solution will fail if the original string contains more than 15 digits, since a number of such length would be beyond Excel’s limitations.

There are two main solutions to this problem and, although I shall present the formulas for both, I will restrict my deconstruction to just one of these. In fact, the one I shall dissect is by far the shorter and more efficient of the two, as well as being, as far as I know, still not that well-known. In fact, where questions of this nature arise on the various Excel forums around the internet, it is almost always the other solution which is presented.

True, the alternative construction is not at all obvious, and in fact most readers seeing it for the first time will probably feel a mixture of incredulity and awe. If what I’ve read on the internet is correct, it appears to have been first thought of (at least, a very slight variation of the version I will present) by someone called Lori.

Just before I come to that one, though, here’s the usual method in such cases, which is the following array formula:


where Arry1 is a row-relative Defined Name given by:


Quite a lengthy and resource-heavy construction, then, for what appears on the face of it a reasonably simple task. So let’s have a look at the alternative without further ado, and that is the following array formula:


How does it work?

We should hopefully be quite familiar with the ROW/INDIRECT construction:


which simply generates a list of integers from 1 up to the length of the string in A1, which is 24 in this case, i.e.:


We subtract this array of values from the result of 1+LEN(A1), i.e. 25, so that:


which is:




And so we are passing this array of 24 values to MID as its start_num parameter, which means that:




which is:


as can easily be verified.

Dividing this array of values by 10 gives:


And applying the IFERROR results in:


And we are now finally in a position to process the NPV function over this array. Of course, I should at first explain precisely how this function operates, and why we have the rather strange-looking initial parameter of -0.9.

The first point to mention is that NPV has the nice property that it ignores any blanks within the range passed to it and operates only on any numerical values within that range, and in order from left to right.

I won’t go into too much of an analysis of the financial reasoning behind this function, since it is not particularly relevant to our discussion. Suffice to say that this function, whose syntax is:


is equivalent to calculating the following summation:


Now, with this in mind, and knowing that, in order to generate our desired result, we need to multiply the entries in our array by successive powers of 10 and then sum the result, we can see that, if we choose a suitable value for the rate parameter, this formula will give us precisely that.

Hence the choice of -0.9, since not only is 1-0.9 obviously 0.1, but also, when we take successive powers of 0.1, beginning with an index of 1, we get:


and when these values are reciprocated with unity, we get:


Hence, in our case, the first non-blank entry from our array, i.e. 0.5, will be multiplied by 10, the second (0.4) by 100, the third (0.4) by 1000, and so and and so on.

We then sum these results and so, finally:


results in 818755279445, as required.

Actually, it appears that this set-up may lead to rounding issues in some cases. Indeed, when I formatted the cell contents appropriately for this result, Excel displayed:


As such, it’s probably wise to wrap this construction in e.g. INT, so as to ensure our output is an integer:


Another instalment to follow shortly!


  1. Thank you for this. I have seen this formula before but never seen the explanation presented in the minute detail you are notable for.
    Thank you again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.