View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Remove any letter from a referenced cell

On Thu, 20 Mar 2008 17:52:00 -0700, FiluDlidu
wrote:

I'm not sure how exactly it works, but it works.

That's too bad because I would otherwise play on variations of the same
thing and use it for other applications.

Anyways, thanks for your reply!

"Ron Rosenfeld" wrote:
============================
Option Explicit
Function RemAlpha(str As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "[A-Za-z]+"
RemAlpha = re.Replace(str, "")
End Function
============================
--ron


It works by doing a Replace -- it replaces any character in the class {A-Za-z]
-- which means any letter -- with a null string, or nothing.

In other words, it is doing exactly what you requested -- "Remove any letter
from a referenced cell".

In the example Mike gave you, he decided to keep the non-letters that were in
your cell -- digits, hyphens and the ampersand, and then he came back to keep
the <spaces.

It seems simpler to me to just eliminate the letters, since that was what you
had specifically requested.

So that is what that regex does.

--ron