Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
DJB Scarlets DJB Scarlets is offline
external usenet poster
 
Posts: 1
Default WORD 2003 Complex Replace Problem

I have a complicated Find and Replace problem in WORD 2003 under WIN XP.

I have a word doocement that contains strings similar to the following:
*11(1) [5] [85] [97] [104] [149]; *29(2) [226]

I want to find all entries *11(1) followed by a string of references each
one enclosed in square brackets and the whole "element" terminated by a
semi-colon. Having found them, I want to replace those references which are
less than [145]. So in the example above, I want to end up with:
*11(1) [149]; *29(2) [226]

However if I wanted to remove all references less than, say, [150] then I
would want the result to be:
*29(2) [226]
i.e removing the complete entry including the 11(1) becasue it is now
redundant.

Is it feasible to do this using Find and Replace or must I resign myself to
doing it manually?

Many thanks in advance to anyone who can help.

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default WORD 2003 Complex Replace Problem

You can't do this with replace in a single pass. You may be able to do it
with a sequence of
replace functions, but much depends on how many numbers there are in the
[149] segment. The following macro will work with all numbers from 100 to
199. If you have numbers higher or lower than that then you'll have to
modify or add to the search and replace strings.

The macro is essentially four sequences of replace
100-139, 140-144, 145-149 then 150 to 199
The first two are replaced with nothing, the second two with the contents of
the first two bracketed sections - \1\2

The search pattern - (\*[0-9]{2}\([0-9]\))[
0-9\[\]]{21}(\[14[0-4]\]; )(http://www.gmayor.com/replace_using_wildcards.htm
) assumes that there will always be the same number of digits in the
blocks - *11(1) [5] [85] [97] [104] [149]; - though what the digits are in
all but the last block doesn't matter.

Sub ReplaceList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

vFindText = Array("(\*[0-9]{2}\([0-9]\))[ 0-9\[\]]{21}(\[1[0-3][0-9]\]; )",
_
"(\*[0-9]{2}\([0-9]\))[ 0-9\[\]]{21}(\[14[0-4]\]; )", _
"(\*[0-9]{2}\([0-9]\))[ 0-9\[\]]{21}(\[14[5-9]\]; )", _
"(\*[0-9]{2}\([0-9]\))[ 0-9\[\]]{21}(\[1[5-9][0-9]\]; )")

vReplText = Array("", "", "\1\2", "\1\2")

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute replace:=wdReplaceAll
Next i
End With

End Sub

See http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


DJB Scarlets wrote:
I have a complicated Find and Replace problem in WORD 2003 under WIN
XP.

I have a word doocement that contains strings similar to the
following: *11(1) [5] [85] [97] [104] [149]; *29(2) [226]

I want to find all entries *11(1) followed by a string of references
each one enclosed in square brackets and the whole "element"
terminated by a semi-colon. Having found them, I want to replace
those references which are less than [145]. So in the example above,
I want to end up with: *11(1) [149]; *29(2) [226]

However if I wanted to remove all references less than, say, [150]
then I would want the result to be:
*29(2) [226]
i.e removing the complete entry including the 11(1) becasue it is now
redundant.

Is it feasible to do this using Find and Replace or must I resign
myself to doing it manually?

Many thanks in advance to anyone who can help.




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 22 May 20th 23 08:51 PM
take yet another lesson from wordperfect "reveal codes" wordperfect is superior Microsoft Word Help 5 May 11th 09 07:58 PM
Word 2003: Changing the increase/decrease rate of the indent icon? hayakaw1 Microsoft Word Help 11 December 22nd 08 09:58 PM
Can't see email images using Word 2003 and Outlook 2003 xfile New Users 0 December 24th 05 03:23 AM
Word 2003 Mailmerge problem - works in Word 2000 Rick Robinson Mailmerge 2 April 28th 05 10:16 AM


All times are GMT +1. The time now is 10:40 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"