How do I remove special characters and alphabets in a string ?
qwert1234*90)! ' this might be my cell value
I have to convert it to
123490 ' I mean I have to remove everything but keep only the numbers in string
but it should allow spaces !
qwe123 4567*. 90 ' String with spaces
123 4567 90 ' output should be
I found the vba Replace
- but writing a replace for each character makes my code big. Well let me tell you clearly without hiding anything from you:
- input:
qwe123 4567*. 90
' String with spaces cells(1,"A").value - My idea to do these next:
123 4567 90
' remove characters first keeping white spaces - final output in
A1:A3
123
4567
90
Could you tell me how do remove all characters except numbers and spaces in string?
Thanks In advance
Those two funny codes will do both of your whishes..
Something like this to
main sub
function
You need to use a regular expression.
See this example:
Explanation:
Pattern = "([0-9]| )+"
will match any 0 or more group (+
) containing a number ([0-9]
) or (|
) a space ().
Some more info on the regexp:
Non-re alternative;
For: