Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2014, 05:50 AM
pelagic pelagic is offline How do I perform simple mathematical calculations on numbers in the text Mac OS X How do I perform simple mathematical calculations on numbers in the text Office for Mac 2011
Novice
How do I perform simple mathematical calculations on numbers in the text
 
Join Date: Apr 2014
Posts: 2
pelagic is on a distinguished road
Default How do I perform simple mathematical calculations on numbers in the text

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
Reply With Quote
  #2  
Old 04-07-2014, 05:36 PM
macropod's Avatar
macropod macropod is offline How do I perform simple mathematical calculations on numbers in the text Windows 7 32bit How do I perform simple mathematical calculations on numbers in the text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

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
If you want to limit the macro's scope to just a selected range, change the two instances of ActiveDocument to Selection.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-08-2014, 05:10 AM
pelagic pelagic is offline How do I perform simple mathematical calculations on numbers in the text Mac OS X How do I perform simple mathematical calculations on numbers in the text Office for Mac 2011
Novice
How do I perform simple mathematical calculations on numbers in the text
 
Join Date: Apr 2014
Posts: 2
pelagic is on a distinguished road
Default Solved - thank you!

Thank you VERY much, that solved the problem and saved me a lot of time!
Reply With Quote
Reply

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
How do I perform simple mathematical calculations on numbers in the text Simple Question (Exiting a text box on click) MdCadle PowerPoint 1 05-30-2013 08:30 AM
How do I perform simple mathematical calculations on numbers in the text typing out mathematical notation gib65 Word 2 08-31-2011 02:21 PM
How do I perform simple mathematical calculations on numbers in the text 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

Other Forums: Access Forums

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