View Single Post
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default Macro to remove text

You can get very close to what you want by selecting column D
edit|replace
what: (*) 'open paren, asterisk, close paren
with: (leaveblank) 'don't type anything--nothing!
replace all

The use a helper column of formulas like:

=trim(d1)
(and drag down)

Then convert to values and delete the original column D.

In code, it would look something like:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim myRng As Range
Dim myCell As Range

Set wks = Worksheets("sheet1")

With wks
Set myRng = .Range("D1", .Cells(.Rows.Count, "D").End(xlUp))
End With

myRng.Replace what:="(*)", replacement:="", _
lookat:=xlPart, searchorder:=xlByRows, _
MatchCase:=False

For Each myCell In myRng.Cells
myCell.Value = Application.Trim(myCell.Value)
Next myCell

End Sub


Terry Pinnell wrote:

Could one of the resident macro experts kindly help me to do this
please. There is text in column D of a worksheet. I want to remove
anything that is in brackets, including the brackets.

So this:

A B C D
-- -- --------------- -------------------------------------------
1 P Andrews Sisters Boogie Woogie (1941 version)
2 Q Artie Shaw (1941) Concerto For Clarinet (Parts 1 & 2)
3 R Artie Shaw Dancing In The Dark
4 S Artie Shaw Frenesi

becomes this:
1 P Andrews Sisters Boogie Woogie
2 Q Artie Shaw Concerto For Clarinet
3 R Artie Shaw Dancing In The Dark
4 S Artie Shaw Frenesi

Thanks.

--
Terry, West Sussex, UK


--

Dave Peterson