Req:Extract Number from String

ravi2628

Board Regular
Joined
Dec 20, 2017
Messages
221
Office Version
  1. 365
  2. 2019
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>

Can any help me out
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0
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.
 
Upvote 0
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:
Upvote 0
Solution
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
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,834
Members
449,051
Latest member
excelquestion515

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