View Single Post
 
Old 03-27-2024, 11:58 AM
vivka vivka is offline Windows 7 64bit Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 228
vivka is on a distinguished road
Default

Besides the gmayor's reference provided by Italophile my collection of bookmarks also has another gmayor's reference (I think, they are almost identical):
Replace using wildcards
The following improved code allows finding different chrs/strings in the selected range using the inputbox:
Code:
Sub Test()
Dim oRng As range
Dim myStr As String

    Set oRng = selection.range
    myStr = InputBox("Enter any number of case-sensitive chrs that start the word/string to find", "STRING")
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .text = myStr & "[! ]@" & Chr(13)
        .Format = False
        .Forward = True
        .MatchWildcards = True
        .Wrap = wdFindStop
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        If .Execute Then oRng.Select
    End With
Set oRng = Nothing
 End Sub
Using myStr allows being more specific, e.g. if you want to find 'Y-01.0203.(para mark)' but not 'Yankee(para mark)', you can enter Y-0 (or more chrs) in the inputbox.
Reply With Quote