Extract text on right of various length from cells
And, for the OP's consideration, here is a non-RegEx UDF to do the same
thing...
Function RemDigitsPart(S As String) As String
Dim X As Long
Dim Parts() As String
Parts = Split(S, "(")
For X = 1 To UBound(Parts)
If X 1 Then RemDigitsPart = RemDigitsPart & ", "
RemDigitsPart = RemDigitsPart & Split(Parts(X), ")")(0)
Next
RemDigitsPart = Replace(WorksheetFunction.Trim(RemDigitsPart), " ,", ",")
End Function
Ron: Note the final Replace function call on my UDF... I think you will need
to do that also (or the RegEx equivalent) since the WorksheetFunction.Trim
call will leave a space in front of a comma if there is one or more spaces
between the text and the closing parenthesis.
--
Rick (MVP - Excel)
"Ron Rosenfeld" wrote in message
...
On Wed, 1 Jul 2009 11:22:01 -0700, HammerD
wrote:
Sorry - my mistake... the cells have the text enclosed in parentheses. And
I
want just the text - not the number or parentheses. There may be 3 or
more
words within the parentheses.
(ex: i.e. - 260 (SMALL THINGS), 261 (THINGS)
I'm guessing that you want to retain the commas.
Here is a User Defined Function that will remove all digits, parentheses,
and
extraneous spaces from your string; leaving you with the text, and the
separating commas.
To enter this User Defined Function (UDF), <alt-F11 opens the Visual
Basic
Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this User Defined Function (UDF), enter a formula like
=RemDigPar(A1)
(where A1 contains your string to process) in some cell.
=====================================
Option Explicit
Function RemDigPar(s As String) As String
Dim re As Object
Const sPat As String = "[\d()]+"
Set re = CreateObject("vbscript.regexp")
re.Pattern = sPat
re.Global = True
RemDigPar = Application.WorksheetFunction.Trim _
(re.Replace(s, ""))
End Function
==============================
--ron
|