Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2019, 08:40 AM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default Find and replace text with wildcards

Hi,



How to find below red highlighted text and replace it using Wildcards

With .Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Execute Replace:=wdReplaceAll

Three scenarios - 1) Text with Aphanumberic with special characters 2) Text is in second row and sometimes partial with 1st row and second row 3) There is no Vertical bar (|) to pin point specific text



1 73181500 SCREW (200 NOS) | AB_1234K123
2 73269099 PLATE (16 NOS) |
PL_3617A026
3 73181500 0S1573 BOLT

Last edited by arunchandar9; 06-27-2019 at 02:45 PM.
Reply With Quote
  #2  
Old 06-27-2019, 06:52 PM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

From your description, the first two can be processed with:
Find = [A-Z]{2}_[A-Z0-9]@>
You will need to provide more detail about the 3rd item.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-28-2019, 01:48 AM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Hi,

It works well with first scenario whereas causing error with second

157 73079290 ADAPTER AS.-ELBOW 90 DEG (NON ELECTRICAL) (50 NOS) | PL_361
7A026


173 73079290 ADAPTER AS.-ELBOW 90 DEG (NON ELECTRICAL) (50 NOS)
| PL_3617A026

Below is the code I'm using now. It's not finding above highlighted Text if it's partial with first and second row or in second row


.Text = "([0-9]{1,})[!^13]@| ([A-Z]{2}_[A-Z0-9]@>)*^13"

I know it's complicated. It's a system generated word reports


Regarding 3rd Scenario, I need to find every third text of below contents

1 73181500 0L1352 BOLT

2 73181500 0S1573 BOLT

354 73181500 3215144 BOLT-WHEEL

330 85365020 2552751 SWITCH AS-START

331 40169990 2588917 SLEEVE-HOSE
Reply With Quote
  #4  
Old 06-28-2019, 05:57 AM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The Find code I posted can't possibly cause an error. What may happen if you go splitting the text as your latest post indicates - but wasn't indicated in your first post, is that it may miss part of the relevant match. To overcome that you might use:
Find = [A-Z]{2}_[A-Z0-9^13]{8,9}>
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-28-2019, 06:01 AM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For your third scenario, you might use:
Find = (<[0-9]@ [0-9]{8}) [A-Z0-9]{6,7}( [A-Z]@>)
Replace = \1\2
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 06-28-2019, 11:49 AM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
For your third scenario, you might use:
Find = (<[0-9]@ [0-9]{8}) [A-Z0-9]{6,7}( [A-Z]@>)
Replace = \1\2
Thank you so much!! It works like a charm!!
Reply With Quote
  #7  
Old 06-28-2019, 11:53 AM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The Find code I posted can't possibly cause an error. What may happen if you go splitting the text as your latest post indicates - but wasn't indicated in your first post, is that it may miss part of the relevant match. To overcome that you might use:
Find = [A-Z]{2}_[A-Z0-9^13]{8,9}>
I'm not quite sure why it's not capturing it. Whats {8,9}? This is the addition you made between earlier code. Is this something I need to change? i.e. increase or decrease

Thank you!!
Reply With Quote
  #8  
Old 06-28-2019, 05:53 PM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The {8,9} specifies that the matched string is to be 8 or 9 characters long.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 06-28-2019, 09:27 PM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The {8,9} specifies that the matched string is to be 8 or 9 characters long.
Thank you!

I ran many macros with difference {n,m} values. There is no effect with mentioned lines.
Reply With Quote
  #10  
Old 06-29-2019, 02:58 AM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps, then, your line breaks aren't paragraph breaks. For all I know they may be generated by tabs or manual line breaks.

Without actually seeing a document with some representative content, it can be difficult for anyone to diagnose the issue. Can you attach sub a document to a post ? You can do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 06-29-2019, 03:53 AM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Sure!! Sure!!

Enclosed Mentioned lines in which I faced this issue. It's a 1000 pages word doc I captured these as an example for your visibility.
Attached Files
File Type: docx Word Macro.docx (16.9 KB, 6 views)
Reply With Quote
  #12  
Old 06-29-2019, 03:10 PM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Not only are your 'PL_' and trailing strings like '3617A026' separated by a paragraph break but there's also a string of spaces (i.e. ' ') before the paragraph break. To fix that, do an ordinary Find/Replace, with:
Find = ^w^p
Replace = ^p
before the wildcard Find/Replace.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 06-29-2019, 06:33 PM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Not only are your 'PL_' and trailing strings like '3617A026' separated by a paragraph break but there's also a string of spaces (i.e. ' ') before the paragraph break. To fix that, do an ordinary Find/Replace, with:
Find = ^w^p
Replace = ^p
before the wildcard Find/Replace.
Good Morning,

I hac mentioned below code to find it and still able to see paragraph break in it (actually it has reduced mentioned spaces) Do I need to mention again please?
Enclosed file after running this code for your reference

.Text = "^w^p"
.Replacement.Text = "^p"
.Text = "([0-9]{1,})[!^13]@| ([A-Z]{2}_[A-Z0-9^13]{8,9}>)*^13"
Attached Files
File Type: docx Word Macro.docx (17.1 KB, 8 views)
Reply With Quote
  #14  
Old 06-29-2019, 11:51 PM
macropod's Avatar
macropod macropod is offline Find and replace text with wildcards Windows 7 64bit Find and replace text with wildcards Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In your attachment, you've replaced the string of spaces before the paragraph break, plus the paragraph break, with a single non-breaking space and a manual line break. The Find/Replace expression I posted didn't cause that. As for your question about the code itself, there's no .Execute line and there's nothing to indicate whether you're using wildcards. That said, at least one of the expressions wouldn't work unless you change the .UseWildcards state.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 06-30-2019, 12:25 AM
arunchandar9 arunchandar9 is offline Find and replace text with wildcards Windows 7 32bit Find and replace text with wildcards Office 2013
Banned
Find and replace text with wildcards
 
Join Date: Jun 2019
Posts: 8
arunchandar9 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
In your attachment, you've replaced the string of spaces before the paragraph break, plus the paragraph break, with a single non-breaking space and a manual line break. The Find/Replace expression I posted didn't cause that. As for your question about the code itself, there's no .Execute line and there's nothing to indicate whether you're using wildcards. That said, at least one of the expressions wouldn't work unless you change the .UseWildcards state.
Is that right? I'm just beginner working on Word Macro.

Sorry for pressing you more on Weekend!!


Code:
With wdDoc
  .ConvertNumbersToText (wdNumberAllNumbers)
  With .Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Format = False
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Text = "^w^p"	
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
    .Text = "([0-9]{1,})[!^13]@| ([A-Z]{2}_[A-Z0-9^13]{8,9}>)^13"^p"
Reply With Quote
Reply

Tags
wildcards, word macros

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace text with wildcards Dissecting a hyperlink with Find Replace Wildcards WeyldFalcon Word 4 11-15-2016 12:48 PM
Using wildcards in Find/Replace to change font/case angie450 Word 2 05-26-2016 11:09 AM
Using wildcards how do I Find and Add to, not replace Stargehzer Word 3 01-25-2016 09:14 PM
Find & Replace: Wildcards (except this pattern) tinfanide Word 6 01-26-2014 06:39 AM
wildcards in find & replace to reverse word order jeffk Word 3 11-11-2012 01:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:27 PM.


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