Find and Replace in Selection doesn't work

Anonymous
2023-01-01T23:21:10+00:00

Hello,

Is this STILL a problem in Word? This used to work, more or less, but it doesn't seem to any longer.

I have a document with 100 lines of text (descriptive filenames, actually) I'm processing the lines for printing and need to replace only the first appearance of the text string " - " (or space-hyphen-space) with a tab. There are other instances of this same text string in some of the filenames, so I only want the first appearance to be found and then replaced with a "^t" character.

However, after I've made my selection (which lamely can only be extended to the bottom of the page, not by dragging to the actual end of the document) and started the Find and Replace operation, Word throws away my selection, creates its own that extends to the entire lines, and then Find and Replaces throughout the entire document.

My original Selection:

Results after Find and Replace " - " with "^t" in my Selection:

As can be seen, Word extended the selection to the end of each line and then did the Find and Replace operation.

This is not what I asked for and I can't find any way to make it do what it should do, which is to only Find and Replace within the selection.

This function has "worked" and then "not worked" the entire time Word has existed, and people were complaining about this being broken back in 2015.

Am I doing something wrong, or is this really broken? Any idea of how to perform this operation? I would rather not write a macro to do this, as it's just a one off operation and should have only taken a few seconds to do.

Thanks for your help with this,

Ian J.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} vote
Answer accepted by question author
  1. Jay Freedman 206K Reputation points Volunteer Moderator
    2023-01-02T01:38:19+00:00

    You can do this without selecting anything by doing a wildcard replacement. In the Replace dialog, click the More button and check the box for "Use wildcards". Then enter this expression in the Find What box:

    (^13[0-9]{2,}) - ([A-Za-z])

    and this one in the Replace With box:

    \1^t\2

    Click the Replace All button, and it's all done.

    The Find What expression says to search for a paragraph mark followed by two or more digits, a space, a hyphen, another space, and a letter. The parentheses around the first and last parts make them correspond to the codes \1 and \2 respectively in the Replace With expression. All that changes is the space-hyphen-space replaced with a tab character.

    The reason for the problem you had is that internally, Word sees the column of selected text as a series of discontinuous ranges, one in each line. Although there are a few things Word is programmed to do with a discontinuous selection, such as changing font colors, replacements cannot work with it. That's why the selection is expanded to include all of every paragraph that has a partial selection.

    If you want to know more about wildcard searches, see https://www.gmayor.com/replace_using_wildcards.htm .

    3 people found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 322.1K Reputation points MVP Volunteer Moderator
    2023-01-02T01:33:52+00:00

    Use the following Wildcard replace routine:

    Find what: (^13[0-9]{2}) -

    Replace with: \1^t

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2023-01-02T03:00:37+00:00

    Hello Jay,

    Thanks very much for your solution, it did a good job. A fantastic job compared to where I got to with it.

    I have used the type of selection I made in the past, many times, and it always worked. But something was changed and now it doesn't. I hope that MS fixes this in the future, as allowing the selection to be made followed by a Find a Replace operation, but then disallowing the actual expected functioning and instead replacing it with something that Word goes ahead with when it's not what was intended and creates an erroneous result (with respect to what was expected) is just sloppy work, in my opinion. I wonder if there is actually ever a reason to allow the type of selection I made, unless it includes all the line ending paragraph marks, which would be just the same as a dragged line selection.

    I appreciate your explanation of why Word does this, but in my opinion it should not and I know it did not at least for some extended period in the past, as this is the first time I've stumbled across this not working now.

    Knowing about wildcards enough to use them in this way is something I'd like to avoid, but in this case other than writing a macro, they present the only solution.

    Thanks very much, Jay.

    Ian J.

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2023-01-02T03:04:57+00:00

    Hi Doug,

    Thanks very much for your solution, it works fine. Jay Freedman's worked just a bit better, but yours also does the heavy lifting and I'm grateful for it. I'll try and remember to use wildcards for this type of purpose in the future.

    I won't bother to repeat my rant, other than to say it's my opinion that Microsoft should either remove the arbitrary selection function or fix what happens after it's made. All I want the Find and Replace to look at is the characters in my selection rectangle, so for this purpose I don't need to know or care about why Word currently needs to extend my selection row by row to the ending paragraph marks.

    OK, that was the rant again, but shorter!

    Thanks very much, Doug, I appreciate your help.

    Ian J.

    0 comments No comments