engarea
asked on
Remove all Non Numeric Characters from a cell
Hi i need a solution or Function which i can use to remove all non numric characters from a cell.
For Example if a cell contains $A16 i want to be left with 16.
Your help is appreciated
Engarea
For Example if a cell contains $A16 i want to be left with 16.
Your help is appreciated
Engarea
Engarea
This code kills non numerics and non spaces
- press Alt & F11 to go to the VBE
- Insert Module
- paste the code below
then press Alt & F11 to return to Excel
select your range of interest
Tools - Macro - Macros and doubleclick KillNonNum
Sub KillNonNum()
Dim C As Range, RegEx, i As Long
Set RegEx = CreateObject("vbscript.reg exp")
RegEx.Global = True
RegEx.Pattern = "[^\d\s]+"
For Each C In Selection
C.Value = RegEx.Replace(C.Value, "")
Next
Set RegEx = Nothing
End Sub
Cheers
Dave
This code kills non numerics and non spaces
- press Alt & F11 to go to the VBE
- Insert Module
- paste the code below
then press Alt & F11 to return to Excel
select your range of interest
Tools - Macro - Macros and doubleclick KillNonNum
Sub KillNonNum()
Dim C As Range, RegEx, i As Long
Set RegEx = CreateObject("vbscript.reg
RegEx.Global = True
RegEx.Pattern = "[^\d\s]+"
For Each C In Selection
C.Value = RegEx.Replace(C.Value, "")
Next
Set RegEx = Nothing
End Sub
Cheers
Dave
ASKER
No thats not working, giving me the old #VALUE return
ASKER
there is an error with line,
C.Value = RegEx.Replace(C.Value, "")
Also can you display this as a function so i can type into a cell for example:
=killnonnum("and the chosen cell here")
C.Value = RegEx.Replace(C.Value, "")
Also can you display this as a function so i can type into a cell for example:
=killnonnum("and the chosen cell here")
ASKER
Yeh that is working but need it as a function not a sub
Cheers engarea
Cheers engarea
ASKER
i have increased points to accomodate changing it to a function so i can using as a cell formulae
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Brett,
That's a beaut! The only hitch I found in that is that it preserves embedded spaces.
Would like to remove them too?
- stochastic
That's a beaut! The only hitch I found in that is that it preserves embedded spaces.
Would like to remove them too?
- stochastic
Hi stochastic,
If you want to remove all spaces change
RegEx.Pattern = "[^\d\s]+"
to
RegEx.Pattern = "[^\d]+"
Cheers
Dave
If you want to remove all spaces change
RegEx.Pattern = "[^\d\s]+"
to
RegEx.Pattern = "[^\d]+"
Cheers
Dave
okay, got it. thanks.
in the first case, "remove everything except digits or spaces"
in the second case, "remove everything except digits".
- sto
in the first case, "remove everything except digits or spaces"
in the second case, "remove everything except digits".
- sto
Try using:
=MID(A1,FIND({"1","2","3",
Patrick