Lookup number in text string

retboell

New Member
Joined
Dec 17, 2018
Messages
3
Hi,

I'm searching for a solution to lookup and return the number of a cell/text string. Example:

InputReturn
asd-1234567890123axbf1234567890123
1234567890123_00sajs11234567890123
0-1234567890123sdfjquwe1234567890123
asdasd-1-n12345678901231234567890123

<colgroup><col><col></colgroup><tbody>
</tbody>

The number will always start with 12345 (but the rest varies) and will always be 13 digits. Otherwise it can be mixed with other numbers and text in the cell (see example)

Help is much appreciated!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I think this should work, there might be better ways to do this though.

Try this:
Code:
=MID(A1,FIND(12345,A1),13)

Phil
 
Upvote 0
You are skipping some numbers while including others. What are the rules about that.?For example. what if the input string was:

asdasd-q98765321sdf-n1234567890123rtyg

What should the output be?
 
Upvote 0
Here's a function that will return just numbers:
Code:
Function NumbersOnly(r As Range) As String
vOut = ""
vStr = r.Formula
For i = 1 To Len(vStr)
  If Mid(vStr, i, 1) >= "0" And Mid(vStr, i, 1) <= "9" Then
    vOut = vOut & Mid(vStr, i, 1)
  End If
Next
NumbersOnly = vOut
End Function
 
Upvote 0
The output for this would be 1234567890123 since the number I'm looking for is always 13 characters and always starts with 12345.
 
Upvote 0
Hi,

You already have a formula solution in Post # 2.
 
Upvote 0
Hi
Can I ask you what does line 3
Code:
 r.Formula
do? you did not assign any formula? can you please break it down?
Thank you.

Here's a function that will return just numbers:
Code:
Function NumbersOnly(r As Range) As String
vOut = ""
vStr = r.Formula
For i = 1 To Len(vStr)
  If Mid(vStr, i, 1) >= "0" And Mid(vStr, i, 1) <= "9" Then
    vOut = vOut & Mid(vStr, i, 1)
  End If
Next
NumbersOnly = vOut
End Function
 
Upvote 0
@lezawang
It's not really needed !!
You could use

Code:
vStr = r

OR

Code:
vStr = r.value

OR

Code:
vStr = r.formula
 
Upvote 0
Thank you very much for the help Michael M. I have another question please
Why his function is taking a range as a argument. Should be be a String?

Rich (BB code):
 Function NumbersOnly(r as String) As String 

Thank you once again.
 
Last edited:
Upvote 0
You might want to start your own thread if you have many questions, rather than "hi-jacking" someone else's thread...
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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