Solved

Data Cleansing - Text Manipulation - VBA Code

Posted on 2010-11-09
3
683 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
ID: 34093247
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
ID: 34093273
WOW - That was absolutely amazing
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34093290
Thanks for the grade!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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