Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2024, 02:15 PM
IndianaITGuy IndianaITGuy is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2019
Novice
Searching for the lone string on a line that starts with a particular character
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default Searching for the lone string on a line that starts with a particular character

Given

;TOOL:5 - DIAM:.75 CRAD:0 REF GL:0
;DESC: Q026
;MATL: HSS
M06 T5.5
(UAO,1)
(UIO,Z(-1*L370))
(TCP,5)
G00 X.429 Y-20.9056 Z11. A0. C0. S18000 M03
Z8.8065
G01 Z7.8065 F50.
X-1.571
Y-20.3033 Z7.802 F80. A-.761
Y-19.7012 Z7.7895 A-1.525 C-3.776


Y-19.0993 Z7.769 A-2.288
Y-18.4977 Z7.7405 A-3.051
Y-17.8965 Z7.704 A-3.813
Y-17.296 Z7.6596 A-4.576
Y-16.6961 Z7.6072 A-5.339
Y-16.6045 Z7.5985 A-5.455
Y-16.0054 Z7.5368 A-6.218
Y-15.4072 Z7.4673 A-6.98
Y-15.151 Z7.435 A-7.307
Y-14.5543 Z7.3541 A-8.07
Y-13.9586 Z7.2653 A-8.833
Y-13.4262 Z7.1791 A-9.516
Y-13.3791 Z7.1711 A-9.576
Y-13.1104 Z7.1248 A-9.922
Y-12.7073 Z7.0523 A-10.44
Y-12.3041 Z6.9759 A-10.96
X-1.5754 Y-12.0936 Z6.9348 A-11.176 C-3.682
X-1.5888 Y-11.8832 Z6.8929 A-11.393 C-3.592
X-1.6112 Y-11.6734 Z6.8501 A-11.61 C-3.504

My current algorithm does a search for "X*Y", which in my implementation expects that nonspecific string to exist on one line. In this example, there is a initially single value for X (1.571), and only the other variables change. Eventually, it reverts back to changing X & Y values. I need to be able to search for the unchanging X or Y value and then make a decision on what to do once that is done.

For the life of me, I cannot find the correct VBA syntax for finding a single string that starts with a particular letter (in this case "Y" and ends in a Paragraph Break.
Reply With Quote
  #2  
Old 03-26-2024, 02:32 PM
Italophile Italophile is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

It is more helpful to post an example document than paste text into your question. This enables others to see what is actually in your document, especially non-printing characters like paragraph and line breaks.

You should actually be searching for a line/paragraph break followed by Y, otherwise you’ll find every line that includes a Y. That can be done without wild cards.
Reply With Quote
  #3  
Old 03-27-2024, 06:25 AM
IndianaITGuy IndianaITGuy is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2019
Novice
Searching for the lone string on a line that starts with a particular character
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default

Ok I will try that. Actually I meant a string that starts with "X" and ends with a paragraph break. I thought I had edited that yesterday. I have attached a snippet of relevant text. Anything above doesn't matter and what follows is hundreds of similarly configured lines. What I was trying to sole at the moment is how to construct a proper Find statement in VBA to find one single string by itself on a line (paragraph in Word, I guess) that starts with a particular character.
Attached Files
File Type: docx Paul - Sample Code1.docx (13.9 KB, 1 views)
Reply With Quote
  #4  
Old 03-27-2024, 07:32 AM
Italophile Italophile is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

By searching for a line/paragraph break followed by Y you’ll know that it is preceded by a line with only an X value.
Reply With Quote
  #5  
Old 03-27-2024, 07:57 AM
IndianaITGuy IndianaITGuy is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2019
Novice
Searching for the lone string on a line that starts with a particular character
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default

Finding a line/paragraph break followed by the character "Y" would only find you a string on a particular line that starts with "Y", but not necessarily the only word on that line? It seems to me it would return True for

Big Fish
Yellow Dog

and

Big Fish
Yankee



Right?
Reply With Quote
  #6  
Old 03-27-2024, 10: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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi! It's not difficult:
Code:
Sub Test()
Dim oRng As range
    Set oRng = selection.range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .text = "Y[! ]@" & 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
Modify the code to meet your needs.
Reply With Quote
  #7  
Old 03-27-2024, 11:55 AM
IndianaITGuy IndianaITGuy is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2019
Novice
Searching for the lone string on a line that starts with a particular character
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Hi! It's not difficult:
Code:
Sub Test()
Dim oRng As range
    Set oRng = selection.range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .text = "Y[! ]@" & 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
Modify the code to meet your needs.

You have me at a disadvantage with the value of .Text. I've looked but nothing good really jumped out at me with regard to special characters. Microsoft Help was not much. What is a good reference for all such special codes when searching for text? I've seen combinations of [], (), /, \, *, whatever. I just want to be able to recognize when there is one, specific word/string alone on a line that starts with a letter of my choosing. In my case it will be an X or Y. No whitespaces in this string.
Reply With Quote
  #8  
Old 03-27-2024, 11:57 AM
Italophile Italophile is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Finding and replacing characters using wildcards
Reply With Quote
  #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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
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
  #10  
Old 03-27-2024, 12:43 PM
IndianaITGuy IndianaITGuy is offline Searching for the lone string on a line that starts with a particular character Windows 11 Searching for the lone string on a line that starts with a particular character Office 2019
Novice
Searching for the lone string on a line that starts with a particular character
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default

OK, bookmarked. Thanks! I'll play with these.
Reply With Quote
  #11  
Old 03-27-2024, 01:43 PM
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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

You are welcome!
Reply With Quote
Reply



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 06:04 AM.


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