# Identifying numbers from letters

#### Helen

##### Board Regular
If I have a unique part number such as 531916300WZ or 5369445Z, is there a formula that would just give me the numbers? The LEN function would only work if it was the same length, but they're all different.

I have no macro knowledge, so a formula if there is one would be great!

Thanks
Helen

### Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

##### MrExcel MVP
Are the letters always at the end, following the pattern:

DDD...LLL..

where D stands for a digit and L for a letter?

#### BrianB

##### Well-known Member
Assuming that your data always has letters at the end :-
In a macro sheet
'-------------------------------------
Public Function GetNum(S As String)
'- find first letter and split string
For n = 1 To Len(S)
If Asc(Mid(S, n, 1)) > 57 Then
GetNum = Left(S, n - 1)
Exit Function
End If
Next
End Function
'---------------------------------------

Use a formula like this in the worksheet
=getnum(A1)

#### CraigM

##### Active Member
Or if the letters are anywhere within the string:

Function NumbersOnly(sString As String)
Num = ""
For n = 1 To Len(sString)
If Asc(Mid(sString, n, 1)) >= 48 And Asc(Mid(sString, n, 1)) <= 57 Then
Num = Num & Mid(sString, n, 1)
End If
Next
NumbersOnly = Num
End Function

#### SIXTH SENSE

##### Well-known Member

hi!
This removes all the leters in in a combination of letters and numbers.

this assumes that they are found in column A.

try this one

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> RemoveLetters()
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cl <SPAN style="color:#00007F">In</SPAN> Range("A1:a" & Range("a65536").End(xlUp).Row)
tmp = cl.Value
cl.Value = ""
<SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> Len(tmp)
<SPAN style="color:#00007F">If</SPAN> IsNumeric(Mid(tmp, i, 1)) <SPAN style="color:#00007F">Then</SPAN>
cl.Value = cl.Value & Mid(tmp, i, 1)
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">Next</SPAN> cl
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

##### MrExcel MVP
Geez. All that VBA...

#### XL-Dennis

##### Well-known Member

I have no macro knowledge, so a formula if there is one would be great!

I do agree with You although I'm a VBA-helper on this board :wink:

At least I try to avoid to apply VBA where it is obvious that there might exist a formula-solution and/or that OP clearly ask for a formula.

Hey man - When will You "convert" to the general trend to apply VBA on everything

Take care and keep up the good function/formula-approach!
Dennis

#### tusharm

##### MrExcel MVP
It would help if you could clarify the problem as requested by Aladin. However, if you have the functions at http://www.tmehta.com/regexp/add_code.htm installed, you could use =RegExpSubstitute(A36,"[^\d]","") to remove all non-digits irrespective of their location.
Helen said:
If I have a unique part number such as 531916300WZ or 5369445Z, is there a formula that would just give me the numbers? The LEN function would only work if it was the same length, but they're all different.

I have no macro knowledge, so a formula if there is one would be great!

Thanks
Helen

#### Helen

##### Board Regular
Hello all,

Thanks to all who have been helping!

Tusharm, I have been onto the site you suggested www.tmehta.com/regexp/add_code.htm, and am confused as it sounded like I'd have to actually install something, whereas there is just a code on this page? Otherwise the formula RegExpSubstitute sounds like a useful formula!

Thanks again to all for helping

Helen
ps - Xl-Dennis, fancy coming to England to teach me VBA?!!!

##### MrExcel MVP
Helen said:
...
aaREMOVER NumPart.xls
ABCD
13205624z3205624
21234512345
3231ret231
4
Helen

The formula in B1 is:

=--SUBSTITUTE(A1,SUBSTITUTE(A1,LEFT(A1,SUMPRODUCT((LEN(A1)-LEN(SUBSTITUTE(A1,{".",0,1,2,3,4,5,6,7,8,9},""))))),""),"")

Replies
5
Views
372
Replies
12
Views
734
Replies
6
Views
139
Replies
5
Views
139
Replies
3
Views
110

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,152,817
Messages
5,772,456
Members
425,760
Latest member
paphon

### 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.

### Which adblocker are you using?

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

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