![]() |
|
#1
|
|||
|
|||
![]()
Hi all,
Currently, I'm using the following macro to delete numbers from a document. Code:
Sub Macro111112() With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Text = "[0-9]{1,2}" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub Below is a sample of the information in the document. Start here: 42 The foundation is built on the 43 now this is what is this is this interesting here 44 ok if you look at age 39 you see formula at the top 45 the vertebrae one of the segments of the spinal column there are 33 vertebra and 46 End Here: Therefore, this macro will delete all the numbers in the document. My goal is to be able, with your help, to only delete the numbers outside the text. For example, after number 44, you see the following text: "ok if you look at age 39 you see formula at the top". Basically, I want the macro to delete numbers 42,43,44,45 and 46 but not number 39 or 33, which is within the sentence or line. Hope this is not confusing. Thanks!!! |
#2
|
||||
|
||||
![]()
Try:
.Text = "^13[0-9]{1,2}^13"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
![]()
Or by macro as requested
Code:
Sub Macro1() Dim orng As Range Set orng = ActiveDocument.Range With orng.Find Do While .Execute(FindText:="[0-9]{1,2}", MatchWildcards:=True) If orng.Start = orng.Paragraphs(1).Range.Start Then orng.Text = vbCr ' or orng.Text = "" ' might be better? End If orng.Collapse 0 Loop End With End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
![]()
Hi Macropod & GMayor,
Thank you for your support, assistance, and the macro (code). Working great! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Spell check macro within macro button field doesn't work in one document | samuelle | Word VBA | 0 | 07-20-2016 02:27 AM |
Macro to add title in header is missing text once macro is run | shawnee24 | Word VBA | 3 | 05-27-2015 12:35 PM |
![]() |
LadyAna | Word | 1 | 12-06-2014 10:39 PM |
Macro Needed to bold specific lines and Macro to turn into CSV | anewteacher | Word VBA | 1 | 05-28-2014 03:59 PM |
custom icon, undo/redo for macro, permanent macro | Rapier | Excel | 0 | 08-05-2013 06:30 AM |