Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2017, 09:11 PM
Guessed's Avatar
Guessed Guessed is offline Keeping just the rows with specific word (BUT KEEP THE TITLE) Windows 10 Keeping just the rows with specific word (BUT KEEP THE TITLE) Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Rather than deleting the rows, I would recommend you hide them from view. The following code does that in the document you posted.
Code:
Sub HideUnwantedRows()
  Dim sText As String, aTbl As Table
  Dim iRow As Integer, aRng As Range
  
  sText = InputBox("What text are you searching for?")
  For Each aTbl In ActiveDocument.Tables
    aTbl.Range.Select
    If aTbl.Range.Paragraphs(1).Style = "Agente" Then
      Set aRng = aTbl.Range
    ElseIf InStr(aTbl.Range.Text, sText) > 0 Then 'if there is at least one row
      For iRow = aTbl.Rows.Count To 1 Step -1
        If Not InStr(aTbl.Rows(iRow).Range.Text, sText) > 0 Then  'not this row
          aTbl.Rows(iRow).Range.Font.Hidden = True
        End If
      Next iRow
    Else
      If Not aRng Is Nothing Then 'hide both tables
        aRng.End = aTbl.Range.End
        aRng.Font.Hidden = True
        Set aRng = Nothing
      Else    'table is standalone
        aTbl.Range.Font.Hidden = True
      End If
    End If
  Next aTbl
  With ActiveWindow.View
    .ShowAll = False
    .ShowHiddenText = False
  End With
End Sub
Because the content is only hidden, it can be restored to view by doing a Select All and then going into the Font dialog ant turning off the Hidden attribute.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 05-26-2017, 07:59 AM
Kopko Kopko is offline Keeping just the rows with specific word (BUT KEEP THE TITLE) Windows 10 Keeping just the rows with specific word (BUT KEEP THE TITLE) Office 2013
Novice
Keeping just the rows with specific word (BUT KEEP THE TITLE)
 
Join Date: May 2017
Posts: 12
Kopko is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Because the content is only hidden, it can be restored to view by doing a Select All and then going into the Font dialog ant turning off the Hidden attribute.
Man, this solution is f****ng awesome! Thanks!!
I will take advantage of your good will... I have another task to do in this same document:

If you see the tables with data, the last column will always be "Serv/Rec." and below that a link to a legend like "Ser02".

If you go to the last table, there will the definition of this expression. I also have to keep this definition and hide (or delete) the rest that is not used. Is it still possible?

If this is asking too much, I already thank you for life! This was really awesome. I'm studying to do this by myself. Thanks a lot for your code!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Open file which contains specific words in title Nick70 PowerPoint 2 06-08-2016 06:55 AM
Keeping just the rows with specific word (BUT KEEP THE TITLE) Formatting all tables in doc with specific word in title jeffreybrown Word VBA 2 05-01-2016 06:05 PM
Copying specific columns of a table to WORD and deleting rows ffinley Word VBA 5 12-07-2015 04:01 PM
Export calendar events from multiple calendars with specific title rasmus Outlook 0 02-06-2015 01:58 AM
Extracting specific rows sbdk82 Excel 4 09-07-2014 10:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:35 AM.


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