Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2018, 09:44 AM
ballpoint ballpoint is offline Find and replace numbers (up to three digits) Windows 10 Find and replace numbers (up to three digits) Office 2016
Advanced Beginner
Find and replace numbers (up to three digits)
 
Join Date: Sep 2017
Posts: 42
ballpoint is on a distinguished road
Default Find and replace numbers (up to three digits)

I have a number of citations devoid of a title, but cited only as 'yearbook 1906, p. 122' or something like that. I would need to match these citations with the actual title of the contribution.



Now, I have the titles and the extent of the contributions: I know, for example, that one specific contribution goes from page 2 to page 136. How can I replace all of the instances citing 'Yearbook 1906, p. [2 to 136]' match?

I have quite a few of those, so ideally I would not like to do it manually.

I know that traditional regexes do not deal well with this sort of problems. There exist solutions like this one: http://gamon.webfactional.com/regexn...angegenerator/

However, I am wondering if something can be attained within Word / Excel.

Any help would be much appreciated!
Reply With Quote
  #2  
Old 06-12-2018, 12:25 PM
d4okeefe d4okeefe is offline Find and replace numbers (up to three digits) Windows 10 Find and replace numbers (up to three digits) Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

Do the citations exist inside of a Word document? (You mention Excel, so it's not clear.) If so, we can probably come up with a wildcard find/replace solution. Perhaps you can give a precise sample of the text you want to change?
Reply With Quote
  #3  
Old 06-13-2018, 03:34 AM
ballpoint ballpoint is offline Find and replace numbers (up to three digits) Windows 10 Find and replace numbers (up to three digits) Office 2016
Advanced Beginner
Find and replace numbers (up to three digits)
 
Join Date: Sep 2017
Posts: 42
ballpoint is on a distinguished road
Default

They ultimately be stored in an Excel column, but of course that can be easily pasted into Word, so either that is perfectly fine. Word seems easier to work with in this regard, so let us assume that is the scenario.

A sample text to be a citation of a contribution spanning from page 2 to 137 in a given Yearbook. A text could be replaced could be either

Code:
yearbook 1906, p. 24
or

Code:
yearbook 1906, p. 122
Both would have to be replaced by a specific name of a contribution in those yearbooks. Like

Code:
Author1, ArticleTitle1,  YB 1906, p. 2-137
If regex syntax weren't what it is like, I would just have to search, say, YB 1906, p. [2-137] to match it. But regexes work differently, as far as I know (hence my link). I could go through that process, but it is time consuming. Is there any way around in word?

Thanks!
Reply With Quote
  #4  
Old 06-13-2018, 08:58 AM
d4okeefe d4okeefe is offline Find and replace numbers (up to three digits) Windows 10 Find and replace numbers (up to three digits) Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

With VBA, you can probably simply find and replace with wildcards, rather than use the <Microsoft VBScript Regular Expressions 5.5> library. Although you could use that too. The advantage of regex, in my experience, is that it allows you to identify substrings of zero or more instances, whereas Word's wildcards do not.

For the example you give, you can do something like this with Wildcards

Code:
Sub find_replace_yearbook()
    Dim d As Document: Set d = ActiveDocument
    Dim r As Range: Set r = d.Content
    
    Dim Author1 As String, ArticleTitle1 As String
    Author1 = "NameOfAuthor"
    ArticleTitle1 = "NameOfArticle"
    
    r.Find.ClearFormatting
    r.Find.Replacement.ClearFormatting
    r.Find.Text = "yearbook ([0-9]{4}, p. )[0-9]{1,}"
    r.Find.MatchWildcards = True
    r.Find.Replacement.Text = Author1 + ", " + ArticleTitle1 + ", YB \1" + "2-137"
    r.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace numbers (up to three digits) Find and Replace - How to insert brackets around all numbers in a doc Natedogg Word 2 05-21-2015 07:16 AM
Find and replace BETWEEN numbers WordUser2015 Word 4 12-19-2014 02:09 PM
find and replace consecutive numbers kpl_39 Word 1 06-07-2013 05:04 AM
Find and replace numbers (up to three digits) Find & Replace formula for numbers? Griff Word 4 04-18-2011 02:47 AM
Find and replace page numbers in body of text tollanarama Word 3 02-13-2011 06:00 AM

Other Forums: Access Forums

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