Find 5 Letters in Text String

djayhawk

New Member
Joined
Jan 14, 2014
Messages
11
Hello,

I have a list of text strings and I'm looking to only return 5 digit numbers from them. They vary in length and position and sometimes there are numbers that are longer than 5 digits (I don't want these). Is there a formula that might work for doing this

Here is an Example. I want the red

IC--65543--12#
67890-Beach--7645712
RB#$12097**
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How about a custom Function ?
Insert this into a standard module
Code:
Function FD(s As String) As String
With CreateObject("VBScript.RegExp")
  .Pattern = "(\d{5})"
  If .Test(s) Then FD = .Execute(s)(0).SubMatches(0)
End With
End Function




Excel 2003
AB
1IC--65543--12#65543
267890-Beach--764571267890
3RB#$12097**12097
Sheet1
Cell Formulas
RangeFormula
B1=FD(A1)
B2=FD(A2)
B3=FD(A3)
 
Upvote 0
Previosu function can give incorrect data, use this one
Code:
Function FD(s As String) As String
With CreateObject("VBScript.RegExp")
  .Pattern = "(?:^|\D)(\d{5})(?!\d)"
  If .Test(s) Then FD = .Execute(s)(0).SubMatches(0)
End With
End Function
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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