Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2012, 09:20 PM
ubns ubns is offline Macro - replace with condition Windows 7 32bit Macro - replace with condition Office 2010 32bit
Competent Performer
Macro - replace with condition
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default Macro - replace with condition

Hi

I have the following code which replaces the .00 with blanks (nothing). In otherwords it removes .00 from the document.

But currently it is removing ".00" if it find anywhere such as .008 will change to 8.

I only want to change if ".00" is like 5.00. so only in this case it should remove ".00".


Sub find()
With Selection.find
.Text = ".00"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Selection.find.Execute replacewith:="" not required as the code is there.
Selection.find.Execute Replace:=wdReplaceAll


End Sub
Reply With Quote
  #2  
Old 05-02-2012, 12:52 AM
macropod's Avatar
macropod macropod is offline Macro - replace with condition Windows 7 64bit Macro - replace with condition 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

hi ubns,

Three things:
1. When posting Word-related questions, please post in the appropriate Word forum (the Word VBA forum in this case).
2. When posting code, please use the code tags on the 'Go Advanced' tab, with properly-formatted code.
3. Don't use Reserved words like 'find' for a macro's name.

Try:
Code:
Sub DeleteCents()
Application.ScreenUpdating = True
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ".00>"
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = True
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
macro or find/replace JamesVenhaus Word 2 02-27-2012 03:34 PM
Macro to replace From Address in Outlook RlcZek113524 Outlook 0 06-08-2011 02:20 PM
Macro - replace with condition Macro to Replace Fonts ballj_35 Word 3 05-10-2011 01:10 AM
Macro - replace with condition check with condition karti Word 2 03-15-2011 06:06 AM
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:42 PM.


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