View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Sandy Mann Sandy Mann is offline
external usenet poster
 
Posts: 2,345
Default Macro to Replace/Delete Text Using "Watchword" List?

With the Watchwords in Column A and nothing else, try selecting the range
that you want to delete the words from and running a Macro something like
this:

Sub WatchWords()
Dim LastWord As Long
Dim x As Long

With Selection
LastWord = Cells(Rows.Count, 1).End(xlUp).Row

For x = 2 To LastWord
.Replace What:=Cells(x, 1), Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Next x
End With

End Sub

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"PBJ" wrote in message
...
We have a vendor who sends us spreadsheets listing photo specs. There can
be
several hundred specs in a sheet. Each one of these is accompanied by a
long
list of descriptors: Key terms we use to catalog the photos in our
database.
All of a photo's descriptors appear in one cell, spearated by a vertical
rule
with spaces. An example looks like this:

| Pensive | Pink | Young | adults | Sundress | woman | lady | musing |
wondering | thoughtful | introspective | introspection | thought |
pondering
| pensiveness | contemplative | contemplating | one | person | individual
|
human | alone |


There are many terms used by the vendor, however, that for various reasons
aren't standard for us. Before specs can be fed into the database, these
"bogey descriptors" have to be deleted. (Don't ask me WHY they have to be
deleted: My bosses simply assure me that they do.) I have a long list of
"watchwords" that I check each spec for. If a term in that list appears, i
delete its occurence in the string of descriptors. In the example,
"pensiveness" and "contemplative" are on the list of banned terms, so I
take
them out, leaving

| Pensive | Pink | Young | adults | Sundress | woman | lady | musing |
wondering | thoughtful | introspective | introspection | thought |
pondering
| contemplating | one | person | individual | human | alone |

The list of "banned terms" is now some 200 items long. Up to now, I've
been
doing a find and replace for each one, but obviously even that takes a
long
time with so many terms to enter in.

The question is: Is it possible to write a macro that A) would
automatically
look for and delete all of the terms on my list (which is always
evolving),
and B) could be carried out in whatever range is selected, as opposed to a
fixed range? ("B" is important, because sometime the spreadsheets from the
vendor supplying the specs varies slightly in format.) Unfortunately, it's
a
requirement that key terms be separated as shown, with a space, vertical
rule, and a space. (My list of "banned terms," however, is just a listing
in
the first column of a workbook, each term in a separate cell.) All terms
in
the modified spec record must still occupy one cell. Sigh.

I know all of this is kind of "Brazil"-like, and I don't like thinking
about
the futility of it all--I would just really, really, really appreciate any
suggestions to help make this depressing task go away. Please help!