Macro to insert "number," in front of another number

H

hemway

I have a series of non-consecutive numbers in a Word document (9, 26,
111, 200, 510, 1001, etc.) I am interested in a macro that will fin
all the numbers in a particular range (1-50) and will insert a numbe
and comma and space in front of it like so (1, 10). This is t
represent a chapter number and the corresponding line number. (I a
building a concordance.)

I am not sure how to specify a range of numbers in the macro so tha
the logic would be "insert a 'number, ' before any numbers in the rang
of 1-50."

Or perhaps I could accomplish this task via wildcards and find an
replace
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Use the following:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{1,}", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
If Selection.Range < 51 Then
Set myrange = Selection.Range
myrange.InsertBefore "1, "
myrange.Collapse wdCollapseEnd
myrange.Select
End If
Loop
End With

You will need to modify the If condition, for the various ranges that you
want it to act upon

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

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

Top