Find and Replace: delete a line & find a number >10

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

TWO THINGS

#1 - I have a list that looks like the list below....

able: 1
about: 18
above: 1
accompany: 1
across: 3
actually: 2
adoring: 1

I want Find and Replace to automatically delete each line that equals ":
1"... (i.e.: delete the lines "able: 1" and "above: 1" and "adoring: 1") the
whole line... I cannot seem to get past this -> <(a): 1


#2 - I want Find any number over 20 (i.e.: >20) Or a range of numbers (i.e.:
20 & <40)

Can anyone help?
 
Janis,

Provided that each line in the list is an individual paragraph then yuo
could use a macro something like this:

Sub ScratchMacro1()
Dim oPara As Paragraph
Dim oRng As Range
For Each oPara In ActiveDocument.Range.Paragraphs
If InStr(oPara.Range.Text, ": 1" & Chr$(13)) Then
oPara.Range.Delete
End If
Next
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = ": [0-9]{2,}"
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
If Right(oRng, 2) > 20 And Right(oRng, 2) < 40 Then
oRng.Font.Color = wdColorBlue
oRng.Collapse Direction:=wdCollapseEnd
End If
Wend
End With
End Sub
 
#1. With 'Use wildcards' checked, search for [a-z]@: 1^013 and replace with
nothing

#2. This is trickier. Bear in mind that you are matching strings of digits,
not numbers as such. You could use: [2-9][0-9] for 20 to 99, then
[1-9][0-9]{2,} for 100 onwards. Can't answer about your number ranges
without knowing what they look like.


An alternative approach is to put your list into Excel, using ": " as the
column delimiter. Then it's easy to sort on the number and delete (or
whatever) the rows you don't want. Come to think of it, you could do that in
Word also: replace ": " with tab, then select all and convert text to table,
then sort on column 2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top