Replace with numbers

F

Frantisek Horalek

Hello.

I need to find the text "Number: xxx" and replace it with Ascending
numbers, starting at one given number, all this in the whole document.

I know that I can ask like this:
Start = CDbl(InputBox("What is the starting number?"))

But then I do not know how to loop this (until the end of the
document), although I was looking through these news.
And how to replace with my variable? I do not know how to specify the
expression.

Thank you very much for help

Imagino
 
H

Helmut Weber

Hi Frantisek, alias Imagino,

like this, in principle.
Above all, the example is restricted to the format ###.
Nothing for end users in a professional
environment, but maybe sufficient for a developer,
to reduce typing errors.

Sub test2()
Dim l As Variant
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
start:
l = InputBox("Start at: format ###")
If Not l Like "###" Then
GoTo start
End If
With rDcm.Find
.Text = "Number: xxx"
While .Execute
rDcm.Text = "Number: " & Format(l, "000")
l = l + 1
rDcm.Collapse direction:=wdCollapseEnd
Wend
End With

End Sub
 
F

Frantisek Horalek

like this, in principle.
Above all, the example is restricted to the format ###.
Nothing for end users in a professional
environment, but maybe sufficient for a developer,
to reduce typing errors.

Great! Thank you very much, that's it"
I made some fixes and it serves as I wanted.
 

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