Consulting

Results 1 to 4 of 4

Thread: Macro to move numbers to the end of a sentence

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    While Paul is correct with regard to sentences, and such a task might even be impossible with access to the complete document. However I find that in these forums some people write 'sentence' when they are referring to sentences that form a paragraph. If the text is a complete paragraph, the following macro will format that paragraph if the cursor is placed in it before running it:
    Sub Macro1()
    Dim oRng As Range, oEnd As Range
        Set oRng = Selection.Paragraphs(1).Range
        Set oEnd = oRng.Duplicate
        oEnd.End = oEnd.End - 1
        oEnd.MoveEndWhile ".", wdBackward
        oEnd.Collapse 0
        oRng.Collapse 1
        oRng.MoveEndUntil "-"
        oRng.End = oRng.End + 2
        If Len(oRng.Text) < 11 Then
            oEnd.Text = Replace(oRng.Text, " - ", "")
            oEnd.InsertBefore " ("
            oEnd.InsertAfter ")"
            oRng.Text = ""
        End If
    Set oRng = Nothing
    Set oEnd = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  2. #2
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    2
    Location
    Thank you gmayor. It does work and I did mean one single sentence without additional punctuation per my example.
    Your help is greatly appreciated.

Tags for this Thread

Posting Permissions

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