Adding a number to a sequence of lines ...

S

Smokin

I have a need to append a number to an instrument definition file
according to this scheme:

Original file contains many entries like this

[ Bank 115]
4=PolarisEP ;Regular
5=ModernEP ;Regular
7=PhaseClavi ;Regular
16=DrawbarOrg2 ;Regular
17=MellowDraw ;Regular

for each line that contains "<number>=" I need to add one to the
number and place it after the "=" sign so it looks like this:

<number>=<number + 1><space> something

Then from my example the resulting file would look like this:

[ Bank 115]
4=5 PolarisEP ;Regular
5=6 ModernEP ;Regular
7=8 PhaseClavi ;Regular
16=17 DrawbarOrg2 ;Regular
17=18 MellowDraw ;Regular

This gives me the computers patch number as well as my data list
number for easy reference, if you were curious. The computer counts
up from 0, the data list from 1. I would spend a lot of time manually
changing the contents of my file otherwise, so if you could assist me
with a macro (word 2003) I would be very appreciative!

This is similar to an earlier request, for which a suggested vba
macro was offered, and it worked very well for subtracting one from
the data list number to get the computer number. Thanks for that ...
but it turns out I also needed the data list number (wouldn't you just
know!)
 
G

Greg Maxey

Try:
Sub ScratchMacro()
Dim findText As String
Dim myRange As Range
Dim i As Long
Set myRange = ActiveDocument.Range
findText = "([0-9]{1,}=)"
With myRange.Find
.Text = findText
.MatchWildcards = True
While .Execute
i = (Left(myRange, Len(myRange) - 1)) + 1
myRange.Text = myRange.Text & i
myRange.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
 

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