Removing non #'s from cell (letters, - , #, etc)

Craig92604

Well-known Member
Joined
Nov 7, 2002
Messages
505
I need to remove all non- numbers from cells. I know there is a way to do this but my brain is fried today
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I used a UDF:
Book2
ABCD
1UDF
2test2222
3try1.9this1.9
4t12y.12312.123
5t10y.102310.1023
Sheet1
<font face=Courier New><SPAN style="color:darkblue">Function</SPAN> testVar(myStr<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">String</SPAN>)<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Double</SPAN><SPAN style="color:darkblue">Dim</SPAN> b()<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Byte</SPAN>, i<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Long</SPAN>, myNum<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">String</SPAN>
b = StrConv(myStr, vbFromUnicode)<SPAN style="color:darkblue">For</SPAN> i =<SPAN style="color:darkblue">LBound</SPAN>(b)<SPAN style="color:darkblue">To</SPAN><SPAN style="color:darkblue">UBound</SPAN>(b)
    <SPAN style="color:darkblue">Select</SPAN><SPAN style="color:darkblue">Case</SPAN> ChrW$(b(i))
        <SPAN style="color:darkblue">Case</SPAN> 0<SPAN style="color:darkblue">To</SPAN> 9, "."
            myNum = myNum & ChrW$(b(i))
    <SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">Select</SPAN><SPAN style="color:darkblue">Next</SPAN>
testVar = myNum ^ 1<SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">Function</SPAN></FONT>

Edit: My code formatting evaporated
 
Upvote 0
=SUBSTITUTE(AB13485,RIGHT(AB13485,SUMPRODUCT((LEN(AB13485)-LEN(SUBSTITUTE(AB13485,{0,1,2,3,4,5,6,7,8,9},""))))),"")

Didn't quite work for instance:

77R5158 = 7 WANTED: 775158

A-054-4M = A-05 WANTED: 544

76DB2408 =76 WANTED: 762408

?
 
Upvote 0
I have never used a user defined formula........I right clicked tab and pasted but can't seem to get it to work. Any help walking me thru my first udf would be greatly appreciatted!
 
Upvote 0
Hello again Craig,

In your spreadsheet hit alt-f11 to go to your VBE. Click the Insert Menu Heading -> Module. Paste the posted code in the now opened code module. You may now use this function within the workbook as I did in my example.
 
Upvote 0
Thank you so much Nate! Worked great! I would love to learn more about using vba just not sure where to start?@*$#@#%$
 
Upvote 0
I suppose the following has slightly less processing involved:

<font face=Courier New><SPAN style="color:darkblue">Function</SPAN> testVar(myStr <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Double</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> b() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Byte</SPAN>, i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, myNum <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
b = StrConv(myStr, vbFromUnicode)
<SPAN style="color:darkblue">For</SPAN> i = 0 <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(b)
    <SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> b(i)
        <SPAN style="color:darkblue">Case</SPAN> 46, 48 <SPAN style="color:darkblue">To</SPAN> 57
            myNum = myNum & ChrW$(b(i))
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
testVar = myNum
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,510
Messages
6,125,228
Members
449,216
Latest member
biglake87

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