Req:Extract Number from String

ravi2628

New Member
Joined
Dec 20, 2017
Messages
45
Hi Every One

i have a Query i need to extract numbers from String in the following format

gvsdgsdfgs TT:1000264 & TT:1000273 & (1000167)

<tbody>
</tbody>
1000264

<tbody>
</tbody>
1000273

<tbody>
</tbody>
1000167

<tbody>
</tbody>

<tbody>
</tbody>

Can any help me out
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,388
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Here's a macro you can try. Assumes your Query strings are in col A starting in A1. If you want to extract the numbers as numbers leave the + 0 (in red) in place, but note that it will strip leading zeroes from your numbers. Remove the + 0 to return strings which will leave leading zeroes in place.
Rich (BB code):
Sub ExtractNums()
For i = 1 To Cells(Rows.Count, "A").End(xlUp).row
       With CreateObject("VBScript.RegExp")
              .Global = True
              .Pattern = "\d+"
              If .test(Cells(i, "A")) Then
                     For Each Match In .Execute(Cells(i, "A"))
                            ct = ct + 1
                            Cells(i, ct + 1) = Match + 0  'remove the + 0 to return strings if you have leading zeroes
                     Next Match
              End If
       End With
       ct = 0
Next i

End Sub
 

ravi2628

New Member
Joined
Dec 20, 2017
Messages
45
HI Joeme,

Sorry i dont want VBA Code I need is formula

because The Subordinate dont know how to use this code

but thanks for the giving me the VBA Code.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,679
Office Version
  1. 2010
Platform
  1. Windows
Hi Every One

i have a Query i need to extract numbers from String in the following format

gvsdgsdfgs TT:1000264 & TT:1000273 & (1000167)

<tbody>
</tbody>
1000264

<tbody>
</tbody>
1000273

<tbody>
</tbody>
1000167

<tbody>
</tbody>

<tbody>
</tbody>
If all of the numbers you want to extract are always 7 digits long as in your posted example, then you should be able to use the following formula. Assuming you data starts in cell A1, put this formula in cell B1 and copy it across for as many columns as numbers as you ever expect to have, then copy all those cells down to the bottom of your data...

=LEFT(TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1,"(",":"),":",REPT(" ",300)),COLUMNS($B:B)*300,300)),7)
 
Last edited:

ravi2628

New Member
Joined
Dec 20, 2017
Messages
45
If all of the numbers you want to extract are always 7 digits long as in your posted example, then you should be able to use the following formula. Assuming you data starts in cell A1, put this formula in cell B1 and copy it across for as many columns as numbers as you ever expect to have, then copy all those cells down to the bottom of your data...

=LEFT(TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1,"(",":"),":",REPT(" ",300)),COLUMNS($B:B)*300,300)),7)



thank you sir it fulfilled my request very much
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,316
Members
414,053
Latest member
Dual Showman

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
Top