Extract numbers only from middle of string

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
Is there a formula I can use which will extract the numbers only from the middle of a string?

The string currently looks like this;

Tygoolhou3837T14

I need to be able to extract the '3837' part - this will always be in between 2 letters. The number of letters before may change, but the number after will not, so another example would be;

Pjhdauajbsna25614D07

If it's not possible using a formula then I'm equally to use VBA but I would prefer a formula.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
It is Not an issue per se, had it been a request for a VBA solution, I would not have posted a formula, I would not have posted to this thread at all.

I'm sure someone would be able to help.
Have a nice day!
 
Last edited:
Upvote 0
Guys, thanks to all of you for your suggestions, I have 1 further question now...

How would I use any of those formulas to achieve the same result on a userform, using a textbox value as the value of 'A1'?

I assume a worksheetfunction but I don't know how to do that if someone can assist me?

One way is this
Code:
Function ExtFunc(Str As String)
    Dim I As Long, Pos As Long
    If Len(Str) <> 0 Then
        For I = 1 To Len(Str)
            If IsNumeric(Mid(Str, I, 1)) Then
                Pos = I
                Exit For
            End If
        Next I
    End If
    ExtFunc = Mid(Str, Pos, Len(Str) - Pos - 2)
End Function

The UDF above will do the same thing as the formula ---at least for your problem as described

So if you wanted to put in Textbox2 the value from extracting the numbers from textbox1, you could do something like
Code:
TextBox2.Value =ExtFunc(TextBox1.Value)
where ExtFunc calls the function used for the extraction
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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