Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 03-27-2024, 11:58 AM
vivka vivka is offline Searching for the lone string on a line that starts with a particular character Windows 7 64bit Searching for the lone string on a line that starts with a particular character Office 2016
Expert
 
Join Date: Jul 2023
Posts: 293
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching for the lone string on a line that starts with a particular character Word macro for deleting a line that starts with a specific character + deleting the line before eduardb Word 1 08-10-2022 03:17 AM
How to move a line to another line that starts with a chain selected in the 1st one? gloub Word VBA 24 03-19-2019 03:12 PM
Searching for string on a formula AMD2800 Excel 1 12-17-2014 10:41 AM
Searching for the lone string on a line that starts with a particular character Replace paragraph-marks (line-breaks) in tables with a character-string Aztec Word VBA 2 04-02-2013 10:52 PM
Searching for the lone string on a line that starts with a particular character Finding or searching ^ character in word document shahin3121 Word 2 03-05-2012 06:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft