Share via

Word Move to next

SteveD 430 Reputation points
2026-04-27T20:56:27.62+00:00

Hello from Steve

) 10 G

) 11 G

Objective find the next

What is happening is that it is going back to the beginning

What is required please for the script to find the next please

Sub Horse_Above_10()

Selection.Find.ClearFormatting

Selection.Find.Font.Size = 12

With Selection.Find

    .Text = "\) [0-9]{2,} [A-Z]"

    .Replacement.Text = ""

    .Forward = True

    .Wrap = wdFindContinue

    .Format = True

    .MatchCase = False

    .MatchWholeWord = False

    .MatchAllWordForms = False

    .MatchSoundsLike = False

    .MatchWildcards = True

End With

Selection.Find.Execute

Selection.MoveLeft Unit:=wdCharacter, Count:=1

Selection.Delete Unit:=wdCharacter, Count:=1

Selection.MoveDown Unit:=wdLine, Count:=1
```End Sub

Developer technologies | Visual Basic for Applications

Answer accepted by question author

  1. Q&A Assist
    2026-04-27T20:56:38.55+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The macro is restarting at the beginning because .Wrap = wdFindContinue tells Word to keep searching from the start after reaching the end. To move only to the next match from the current position, use wdFindStop and execute the find in a loop so it continues from the current selection.

    Example adjusted macro:

    Sub Horse_Above_10()
    
        With Selection.Find
            .ClearFormatting
            .Font.Size = 12
            .Text = "\) [0-9]{2,} [A-Z]"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop   'Stop at end; do not continue from top
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
    
        'Find next occurrence from current cursor position
        If Selection.Find.Execute Then
            'Now Selection is on the found text
            Selection.MoveLeft Unit:=wdCharacter, Count:=1
            Selection.Delete Unit:=wdCharacter, Count:=1
            Selection.MoveDown Unit:=wdLine, Count:=1
        End If
    
    End Sub
    

    Key changes:

    • .Wrap = wdFindStop so the search does not wrap to the beginning.
    • Selection.Find.Execute is used once per run to move to the next match from the current cursor position.

    If multiple occurrences must be processed in one run, wrap the Execute and subsequent actions in a Do While Selection.Find.Execute loop, similar to the loop pattern shown in the sample macro in the references.


    References:

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.