Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jul 2008
    Thanked 0 Times in 0 Posts

    Need to increment pre-existing number by 1 (Word 2

    I have lines of text in three Word files. All the lines of text in the Word files are identical to the lines below, except for the 5 digit number in each line of text. What you see below are lines taken from php/MySql records. The records are stored in Word 2003 files prior to uploading.

    I need to increment the pre-existing three digit number in each line of text by 1 from the pre-existing number's current value.

    (`PrevNextNum`,`Source`,`VerseRef`,`Text`,`Index`) VALUES ('34095','ACL','
    (`PrevNextNum`,`Source`,`VerseRef`,`Text`,`Index`) VALUES ('34096','ACL','
    (`PrevNextNum`,`Source`,`VerseRef`,`Text`,`Index`) VALUES ('34097','ACL','
    (`PrevNextNum`,`Source`,`VerseRef`,`Text`,`Index`) VALUES ('34098','ACL','

    Below you see a macro that will find a word in the text, replace the word with a number, and increment the number each time a new word is found. This macro would work in this case but the macro looks for text = PrevNextNumber and does not look for a pre-existing 5 digit number.

    Sub RecordNumberSequencing()
    PreviousRecordNumber = 38020

    Upcount = Upcount + 1

    intCounter = PreviousRecordNumber + Upcount

    'intCounter = intCounter + 1

    With Selection.Find
    .Text = "PrevNextNumber"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    If Not Selection.Find.Execute Then Exit Do
    Selection.Find.Execute Replace:=wdReplaceOne
    Selection.TypeText Text:=intCounter

    End Sub

    Instead of looking the the text PrevNextNumber I need the macro or one like it to look for all five digit numbers in the text line above, replace the five digit number with another number incremented by 1.

    Thank you in advance for any replies.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Need to increment pre-existing number by 1 (Word 2

    In this line, you have specified a literal string of text rather than a variable:
    <hr><code> .Text = "PrevNextNumber"</code><hr>
    If you want to specify a variable, then use the variable name to the right of the = sign. For example:
    <hr><code> myFindWhatText = 12345

    .Text = myFindWhatText</code><hr>
    Does that help?

    Now, I don't understand your requirements completely. Let's say you are looking to do this:

    find 12345 and replace with 23456
    find 12346 and replace with 23457

    You probably do not want to check for 100,000 potential 5-digit values. Is there a range of values you want to find?

  3. #3
    Star Lounger
    Join Date
    Jul 2008
    Thanked 0 Times in 0 Posts

    Re: Need to increment pre-existing number by 1 (Wo

    Thank you for the response. I believe I have a solution. I will check and post the solution upon finalization. Thank you again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts