Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2017, 11:22 AM
rsrasc rsrasc is offline Need Help With this Macro Windows 10 Need Help With this Macro Office 2013
Competent Performer
Need Help With this Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default Need Help With this Macro

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!!!
Reply With Quote
  #2  
Old 02-28-2017, 02:50 PM
macropod's Avatar
macropod macropod is offline Need Help With this Macro Windows 7 64bit Need Help With this Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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

Try:
.Text = "^13[0-9]{1,2}^13"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-28-2017, 09:49 PM
gmayor's Avatar
gmayor gmayor is offline Need Help With this Macro Windows 10 Need Help With this Macro Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #4  
Old 03-02-2017, 06:33 AM
rsrasc rsrasc is offline Need Help With this Macro Windows 10 Need Help With this Macro Office 2013
Competent Performer
Need Help With this Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Hi Macropod & GMayor,

Thank you for your support, assistance, and the macro (code).

Working great!
Reply With Quote
Reply



Similar Threads
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
Need Help With this Macro Macro Question: Need help making a macro to highlight the first word in every sentence 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft