Thread: [Solved] Word Find and Replace Query
View Single Post
 
Old 12-29-2011, 12:45 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,466
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

Hi Brian,

Out of the box, there's nothing in Word's Find/Replace tool that'd do what you're asking. A macro would be required. For example:
Code:
Sub UpdatePrices()
Application.ScreenUpdating = False
Dim RngFnd As Range, SngVal As Single, i As Integer
Set RngFnd = Selection.Range
With Selection.Range
  If Len(.Text) < 4 Then Exit Sub
  On Error Resume Next
  SngVal = CSng(InputBox("By what should each value be multiplied?", "Price Changer"))
  If SngVal = 0 Then Exit Sub
  With .Find
    .ClearFormatting
    .Text = "[0-9,]{1,}.[0-9]{2}>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If .End > RngFnd.End Then GoTo Done
    i = i + 1
    .Text = Format(CSng(.Text) * SngVal, "#,##0.00")
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Done:
Set RngFnd = Nothing
Application.ScreenUpdating = True
MsgBox i & " price(s) updated."
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 12-29-2011 at 12:57 AM. Reason: Bug fix!
Reply With Quote