Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2023, 04:21 AM
paulkaye paulkaye is offline Find-replace macro - I got stuck! Windows 10 Find-replace macro - I got stuck! Office 2016
Advanced Beginner
Find-replace macro - I got stuck!
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default Find-replace macro - I got stuck!

Hi all,


I've tried my best to convert the find-replace knowledge that I've learned from here into a macro, but I just can't get it right. I'm trying to build a macro that will convert all instances of:

.{tab}The {text} according to any one of examples {lownum}-{highnum},

into

.{tab}The {text} according to example {lownum},

In the above:
{tab} represent a tab character (e.g. ^t).
{text} can be any text and should remain as-is. If it is difficult to achieve this without unpredictable results, then it would be ok for this to be a single word.
{lownum}-{highnum} represents a range. Their absolute and relative values are unimportant. The number before the hyphen (i.e. {lownum}) should remain as-is, while the hyphen and the number following the hyphen (i.e. {highnum}) should be deleted.
Reply With Quote
  #2  
Old 03-01-2023, 04:26 PM
Guessed's Avatar
Guessed Guessed is offline Find-replace macro - I got stuck! Windows 10 Find-replace macro - I got stuck! Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,989
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Record yourself doing a Find and Replace with wildcards turned on

Find
according to any one of examples ([0-9.]{1,})-([0-9.]{1,})

Replace with
according to example \1
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-01-2023, 11:46 PM
paulkaye paulkaye is offline Find-replace macro - I got stuck! Windows 10 Find-replace macro - I got stuck! Office 2016
Advanced Beginner
Find-replace macro - I got stuck!
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

Hmm. This is what I did:




but the output seems to be:



The {text} {lownum}according to example ,




For example:



The frog 1according to example ,


I can't figure out why the number is appearing in such a strange place. Any ideas?
Reply With Quote
  #4  
Old 03-02-2023, 05:46 PM
Guessed's Avatar
Guessed Guessed is offline Find-replace macro - I got stuck! Windows 10 Find-replace macro - I got stuck! Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,989
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The () brackets in the Find box define the region of the found text
The \1 in the replace box tells Word where to put the contents of the first () bracketed item

If you are getting 1according then it tells me you put the \1 in the wrong place
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 03-04-2023, 11:09 PM
paulkaye paulkaye is offline Find-replace macro - I got stuck! Windows 10 Find-replace macro - I got stuck! Office 2016
Advanced Beginner
Find-replace macro - I got stuck!
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

I'm with you on that. I included that screenshot of my find-replace window specifically because I expected you'd think I'd typed the strings incorrectly!

But I've identified the culprit: The weirdness occurs if track changes is on. With track changes switched off, your approach works perfectly - thank you!



If you can figure out a way to make this work with track changes switched on, that would be wonderful. (I like to be able to look over the results of a macro each time I run it, in order to verify that it performed as expected.) But if that isn't possible, no worries, and I thank you again for your help.
Reply With Quote
Reply

Tags
find & replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace Macro Need djpemberton Word VBA 2 05-04-2016 07:53 PM
Find-replace macro - I got stuck! Find and Replace Macro amparete13 PowerPoint 3 03-11-2014 05:29 AM
Find-replace macro - I got stuck! Is the following too complex for find/replace macro? bertietheblue Word VBA 12 11-04-2013 05:35 PM
macro or find/replace JamesVenhaus Word 2 02-27-2012 03:34 PM
Find and Replace Macro - A Better Way Tribos Word VBA 0 10-08-2008 03:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:07 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