Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find and replace a number in a macro (Word 2k)

    I want to find and replace a number in a series of numbered paragraphs with a string of text before and after the number. Since ^# doesn't work in the replace box, I need to be somewhat more clever. How can I do this?

    Example 1. blah blah
    2. blah blah

    Becomes:
    some text 1 some more text blah blah
    some text 2 some more text blah blah

    Any ideas?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find and replace a number in a macro (Word 2k)

    If the paragraphs are numbered using the Format | Bullets and Numbering dialog or the Numbering button on the Formatting toolbar, you can't use Find and Replace for this; you must customize the number format in the Bullets and Numbering dialog, or better still, create a custom style with the number format you want.

  3. #3
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and replace a number in a macro (Word 2k)

    The numbering is manual, in the form n.

    I can find the first digit of Number by ^#. Is the best way to find the last digit to search for the trailing period, extending the selection?
    Then I can insert string2 after Number, then Start_of_line and insert string1, looping to the search for ^# again.

    Any better ideas?
    (I thought of this method after I posted & sorry for the pseudocode if this is too mixed up...)

    Saturn

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Find and replace a number in a macro (Word 2k)

    You should be able to do this with a wildcard search
    Find ([0-9].)
    Replace black 1 blue
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and replace a number in a macro (Word 2k)

    Thanks.

    I've tried this both with the find box and with with a macro.

    While the find alone works, the 1 returns an error: replace with text box contains a group number which is out of range.
    So, I tried 0 and even n, and got the same error.

    What works?

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Find and replace a number in a macro (Word 2k)

    Try putting [ square brackets ] round the 1

    StuartR

  7. #7
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and replace a number in a macro (Word 2k)

    Thanks Stuart.

    [1] gives the same out of range error as does 1.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Find and replace a number in a macro (Word 2k)

    Sorry, it was a while since I did this. The correct syntax is...


    Check use wildcards
    Find what: ([0-9])
    Replace with black 1 blue

    Use the ( ) brackets in the find what box to group the elements for use in the replace box.

    StuartR

  9. #9
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and replace a number in a macro (Word 2k)

    That works until I get to 10. Then the 0 is selected, and I get 1black 0 blue.

    How do I select all n digits of an n digit number?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find and replace a number in a macro (Word 2k)

    It seems to work for me without square brackets - see screenshot. The {1,} means: one or more occurrences of the previous character, i.e one or more digits.
    Attached Images Attached Images
    • File Type: png x.PNG (6.6 KB, 4 views)

  11. #11
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and replace a number in a macro (Word 2k)

    Hans,

    You gave me the clue that was needed.
    Find ([0-9]{1,3}). will find any number, up to 3 digits long, followed by a period. (As opposed to {1,} which just finds numbers of the pattern nnn.

    Thanks,
    Saturn

  12. #12
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Find and replace a number in a macro (Word 2k)

    If you put the period after the closing ) then it will not be included in the replacement 1
    If you want the number and period included then you should use ([0-9]{1,3}.)

    StuartR

Posting Permissions

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