Consulting

Results 1 to 3 of 3

Thread: Find Lower-Case But Maintain Letter?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Find Lower-Case But Maintain Letter?

    I can find each paragraph that begins with a lower-case letter by searching for:

    ^13[a-z]

    If modifying the surrounding character/s (removing the paragraph, for example), how do I maintain the original/existing lower-case letter? All my attempts so far have ended up with "[a-z]" within the text...

    Basically I want to be able to turn this:

    That was a.
    great shot.

    ...into:

    That was a great shot.

    Thanks for any help!

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Simple recorded macro with

    1. .MatchWildcards = True

    2. \. 'escapes' the end of sentence period since 'dot' can be a RegEx metacharacter

    3. ^13 for the paragraph mark; ^10 if new line mark

    4. 'Grouping' ( ) around the matching range a-z so that ...

    5. ... the space+\1 in Replacement can refer to what was found in the first (only) grouping



    Sub Macro3()
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
    
        With Selection.Find
            .Text = "\.^13([a-z])"
            .Replacement.Text = " \1"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Excellent. Thanks so much!

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
  •