Thread: select until =
View Single Post
 
Old 01-30-2024, 02:21 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Otherwise, the code should be slightly different:

Code:
Sub Test_Macro()
'Copy a range from the current para's start till after "=" and
'paste it after the para.

Dim oRng As range
    Set oRng = selection.Paragraphs(1).range
    selection.Find.ClearFormatting
    selection.Find.Replacement.ClearFormatting
    With oRng.Find
        .text = "="
        .Replacement.text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        If .Execute Then
            oRng.Start = selection.Paragraphs(1).range.Start
            oRng.Copy
            selection.Paragraphs(1).range.Select
            selection.Collapse wdCollapseEnd
            selection.InsertAfter vbCr
            selection.Collapse
            selection.PasteAndFormat (wdFormatOriginalFormatting)
        End If
    End With
End Sub
Reply With Quote