Identifying numbers from letters

Helen

Board Regular
Joined
Feb 19, 2002
Messages
103
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Are the letters always at the end, following the pattern:

DDD...LLL..

where D stands for a digit and L for a letter?
 
Upvote 0
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)
 
Upvote 0
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
 
Upvote 0
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>
 
Upvote 0
Aladin,

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 :LOL:

Take care and keep up the good function/formula-approach!
Dennis
 
Upvote 0
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
 
Upvote 0
Hello all,

Thanks to all who have been helping!

Aladin, in reply to your question, yes they wil have the pattern of DD..LL.

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?!!!
 
Upvote 0
Helen said:
...Aladin, in reply to your question, yes they wil have the pattern of DD..LL.
...
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},""))))),""),"")
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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