Thread: remove numbers
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default remove numbers

Here is perhaps another one. You had this in your code...

If sChar Like "[0-9]" Then
Else
If sChar = "." Or sChar = "," Or sChar = ";" Then
Else
sStr1 = sStr1 & sChar
End If
End If

It looks like this is ignoring digits, dots, commas and semi-colons. You
could combine the punctuation test with the digit test like this...

If sChar Like "[0-9.,;]" Then
Else
sStr1 = sStr1 & sChar
End If

But here is what I think you will consider the pearl... if you prefix the
characters inside the square brackets with an exclamation sign (!), then the
Like operator will test sChar for any character **not** equal to the rest of
the characters in the list. So, your original If-Then structure can be
reduced to this...

If sChar Like "[!0-9.,;] Then sStr1 = sStr1 & sChar

--
Rick (MVP - Excel)


"Gary''s Student" wrote in message
...
Thanks!

Another pearl for the braclet!
--
Gary''s Student - gsnu200816


"Rick Rothstein" wrote:

sStr1 = Replace(sStr1, "INC", "")
sStr1 = Replace(sStr1, "Inc", "")


The Replace function can be made case insensitive by using its optional
arguments. The functionality of the above two lines of code can be
handled
by this single line of code...

sStr1 = Replace(sStr1, "Inc", "", , , vbTextCompare)

or, if you favor named arguments...

sStr1 = Replace(sStr1, "Inc", "", Compa=vbTextCompare)

--
Rick (MVP - Excel)