Solved

Data Cleansing - Text Manipulation - VBA Code

Posted on 2010-11-09
3
679 Views
Last Modified: 2012-08-13
Hello experts,

I'm looking for VBA code that would remove the text between brackets, including the brackets, so the line:
COTY: CK/ DAVIDOFF: SEQUEL SATURDAYS:  THE BOURNE IDENTITY (2002, PG-13, 119 min,*3/3)
should become:
COTY: CK/ DAVIDOFF: SEQUEL SATURDAYS:  THE BOURNE IDENTITY

The above operation should be applied on every line in a movie list that is supplied in an Excel sheet. Please see below sample of that list:

COTY: CK/ DAVIDOFF: SEQUEL SATURDAYS:  THE BOURNE IDENTITY (2002, PG-13, 119 min,*3/3)
RENAULT: SEQUEL SATURDAYS:  THE BOURNE SUPREMACY (2004, PG-13, 108 min,*1/3)
PETROMIN: THE LAST KING OF SCOTLAND (2006, R, 123 min, +2)
KFC: CONSPIRACY (2008, R, 90 min, 2/4)
WOLF CREEK (2005, R, 99 min, 4/4)
THE SILENCE OF THE LAMBS (1991, R,118 min, *3/4)
JOY RIDE (2001, 97 min,*3/4)
FORD: MONDAY NIGHT PREMIERE: THE HITCHER (2007, R, 84 min, 1/4)
THE TEXAS CHAINSAW MASSACRE (2003, R, 98 min, 6/6)
POWER HORSE: DOOM (2005, R, 100 min, +2)
SNICKERS: HOME OF MOVIES: THE BOOK OF ELI (2010, R, 118 min, 1/6)
RAMBO IV (2008, R, 92 min,*1/99)
KIA: DARK BLUE (2002, R, 118 min,*4/4)
STC: 16 BLOCKS (2006, 105 min, *1/4)
ADIDAS: NAKED WEAPON (2002, R, 92 min, *1/99)
WRIGLEYS: TORNADO! (1996, PG, 89 min,1/3)
STC:  DOMINO (2005, R, 127 min,5/99)
GRAND CHEROKEE: CHILLER: HOSTEL (2005, R, 94 min, 1/3)
CREEP (2004, R, 85 min,*1/99)
PETROMIN: THE MANCHURIAN CANDIDATE (2004, R, 129 min,*1/4)
SLITHER (2006, R, 95 min, *1/6)

I'm also attaching a sample Excel sheet for your reference.

The VBA code should read line by line and remove the entire part between brackets, which is the release year of the movie, Rating, Duration, etc..)

The good news is that you will only have one left "(" and one right ")" brackets, so your code should be straightforward in trying to locate the position of those brackets in the entire string and simply do a replace or any other text manipulating function to remove it.

Also, the list is in one column, so I can select the colum, and then run the code with :


For each cell in Selection
.....
Replace ....
....
next cell

End sub


Appreciate your help
 Movie-List.xlsx
0
Comment
Question by:Mehawitchi
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
broomee9 earned 500 total points
Comment Utility
No need for a loop.  Try this:

Option Explicit

Sub RemoveParens()
    Columns("A:A").Replace What:="(*)", Replacement:="", LookAt:=xlPart
End Sub

Open in new window

Example.xlsm
0
 

Author Comment

by:Mehawitchi
Comment Utility
WOW - That was absolutely amazing
0
 
LVL 24

Expert Comment

by:broomee9
Comment Utility
Thanks for the grade!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now