Extracting a sequence of numbers within a string

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,275
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

I have a series of variable length strings in an Excel list that look a bit like this:

Code:
promote Trans.no: 1173331 by bobsmith

I want to be able to extract the numeric element of the string which is usually, but not always eight characters

I know however that the number will always be preceded by "Trans.no: " and always followed by " by " as in the above example.

Any suggestions?

As always, thanks in advance

Pete
 
Yes although if you have more than 15 digits of precision in your numbers, the additional numbers will change to 0.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Rory,

Thank you - yes, that works too, although I understand it even less than I did Rick's..! :)

I assume that I adjust the 15s to whatever the maximum length of my numerical sequence is likely to be?
As Rory points out in Message #11, there is a limit to the precision of the number his formula will return (my formula has no such limit), but your post does not seem to indicate you will be approaching that limit; however, I did want to note for you, in case it could matter, that Rory's formula will not preserve leading zeroes for numbers having one or more zeroes at the beginning. I would also point out that Rory's formula is Volatile (my formula is not) which could matter if you plan to apply the formula to a lot of cells. We can modify Rory's formula to make it non-Volatile though (at the cost of adding two more function calls) like this...

=-LOOKUP(2,-LEFT(MID(A2,FIND("Trans.no: ",A2)+10,15),ROW(INDEX(A:A,1):INDEX(A:A,15))))
 
Upvote 0
Rick, Rory, Istvan,

Thanks for all your assistance. I am now able to successfully extract the data I require.

More usefully, I understand how each of the suggestions that you have provide work!

Pete
 
Upvote 0
I expect to see NPV appearing in a shortest formula challenge in the near future. ;)
 
Upvote 0
Strange indeed, but the most original solution I've seen in a long time. Wonderful!!

I expect to see NPV appearing in a shortest formula challenge in the near future. ;)

Yes, a very original and clever formula!

But I'll tell you a secret (do not tell anyone ;))

Despite knowing this formula for sometime now, every time I use it I can not fully understand how it works :confused:

M.
 
Upvote 0
Yes, a very original and clever formula!

But I'll tell you a secret (do not tell anyone ;))

Despite knowing this formula for sometime now, every time I use it I can not fully understand how it works :confused:

M.

Yes. I've tended to avoid all "financial" formulas in Excel until now, mainly because I don't have much understanding of that field. :confused:

Perhaps it's time to start looking into them though, especially if they can produce "non-financial" solutions such as this!!

Cheers
 
Upvote 0
quote_icon.png
Originally Posted by Marcelo Branco
=NPV(-0.9,,IFERROR(MID(A2,1+LEN(A2)-ROW(INDIRECT("1:"&LEN(A2))),1)%,""))



Strange indeed, but the most original solution I've seen in a long time. Wonderful!!

Thanks for sharing!

Cheers

When I first met the problem of extracting any number of digits from a mixed alphanumeric string with a formula in excel and tried to find a general solution (with no success), I wondered who had invented this brilliant solution (an accountant, a bank officer?) and could trace this use of NPV back to 2008 by Google.
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,945
Members
449,198
Latest member
MhammadishaqKhan

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