Sam,
Just do a variation of the routine you set up to find and select only
numbers. The outer loop remains the same. The internal part -- checking a
given string and keeping only non-numbers -- would look something like the
code below. The concept is simple -- just intialize a new null string, then
check the characters of the old string one at a time. If the character is
not a number, add it to the new string. Check for numbers by lookkng at the
ASCII value of the character. The code uses the Asc function to set the
range of "number" characters (in case you were like me and don't remember
off the top of your head that "0" is ASCII 48). Can be sped up by
hard-coding values and eliminating redundant variables (at the expense of
code readability).
ASC_0 = Asc("0") ' ASCII value for character zero
ASC_9 = Asc("9") ' ASCII value for character nine
myLen = Len(myText) ' Length of old string being evaluated. Assumes
passed string is in variable "myText"
newText = "" ' Initialize new string. Build it charcater by
character from the old string
' Cycle through each character of old string. If ASCII value indicates it is
not a number, then add it to the new string
For k = 1 To myLen
myChar = Mid(myText, k, 1) ' Pick the character
myAsc = Asc(myChar) ' Find character ASCII value
' Check if ASCII value is in the range of numbers. If it is not, add the
character to the new string.
If (myAsc < ASC_0) Or (myAsc > ASC_9) Then
newText = newText & myChar
End If
Next k
' New string is in variable "newString"