Microsoft Office Forums Find a text and delete the line above

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2019, 07:26 AM
Dzib Dzib is offline Find a text and delete the line above Windows 10 Find a text and delete the line above Office 2019
Novice
Find a text and delete the line above
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default Find a text and delete the line above

Hi,



I need help on a little piece of code.
I have a document made of multiples tables with titles between them. I would like to delete one line above each title to reduce the space between each table.
The title is not in the table as I've converted them to text before.
Any help would be appreciated...

Thanks

Edit: all the titles contains a same word.

Last edited by Dzib; 09-10-2019 at 11:21 AM.
Reply With Quote
  #2  
Old 09-10-2019, 12:27 PM
gmaxey gmaxey is offline Find a text and delete the line above Windows 10 Find a text and delete the line above Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 936
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngIndex As Long
Dim oRng As Range
  For lngIndex = ActiveDocument.Tables.Count To 2 Step -1
    Set oRng = ActiveDocument.Tables(lngIndex).Range
    oRng.Collapse wdCollapseStart
    oRng.Move wdParagraph, -1
    'By your description, the range should now be defined at the table title.
    If Not oRng.Paragraphs(1).SpaceBefore = 0 Then oRng.Paragraphs(1).SpaceBefore = 0
    If Len(oRng.Paragraphs(1).Previous.Range) = 1 And Not _
       oRng.Paragraphs(1).Previous.Range.Information(wdWithInTable) Then
      oRng.Paragraphs(1).Previous.Range.Delete
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a text and delete the line above Delete Line of Bookmark if the Text is Empty ljg713 Word VBA 1 12-21-2015 04:27 PM
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Find a text and delete the line above Search for text then delete line konopca Word VBA 2 06-07-2012 02:44 AM
Find a text and delete the line above Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Find a text and delete the line above Need help on Macro 03- Find text - if text is blank then remove line simpleonline1234 Word VBA 1 02-25-2011 02:28 AM


All times are GMT -7. The time now is 03:23 AM.


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