![]() |
|
|
|
#1
|
|||
|
|||
|
I have a Word doc which is a stand alone index to be added to an existing project. The index is five pages long and is in two columns with the following format: effluent treatments 76, 77–78 England, UK 17, 23, 79, 84, 90 At the moment all the numbering is out and I need to subtract 13 from each number. Am I correct in understanding that you cannot use regular expressions to perform mathematical calculations or is there a simple solution? I have tried: Using find and replace with find: ([0-9]{1,2}) replace: ^& (13) to add (13) after all the numbers then selecting all the text and running the ToolsCalculate command. Even if I add spaces either side of each number I keep getting a syntax error? Is it possible to automate this technique using a Macro? Any suggestions gratefully received! Thanks |
|
#2
|
||||
|
||||
|
You can't do this with a Find/Replace on its own. You can if you use it in a macro, though:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
Set Rng = ActiveDocument.Range
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "[0-9]{2,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
If Not .InRange(Rng) Then Exit Do
If .Text > 13 Then .Text = .Text - 13
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thank you VERY much, that solved the problem and saved me a lot of time!
|
|
| Tags |
| calculation, mathematics, toolscalculate |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to do Calculations In a Text Box? | SteveF | Word | 4 | 09-27-2013 08:34 AM |
Simple Question (Exiting a text box on click)
|
MdCadle | PowerPoint | 1 | 05-30-2013 08:30 AM |
typing out mathematical notation
|
gib65 | Word | 2 | 08-31-2011 02:21 PM |
Perform Calculations using List boxes
|
Jennifer_Falcon | Word VBA | 6 | 07-26-2011 10:49 AM |
| How to fill a cell with random numbers to do calculations? | zanat0s | Excel | 1 | 06-13-2011 10:33 AM |