View Single Post
 
Old 05-27-2017, 10:09 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
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

It seems to work when stepping through but not running at speed.

Try this version which specifies the last table explicitly
Code:
Sub HideUnwantedRows3()
  Dim sText As String, aTbl As Table, aHL As Hyperlink, aCell As Cell
  Dim iRow As Integer, aRng As Range, aRngTgt As Range, aRow As Row
  Dim sRefs As String, aRowRng As Range, sTag As String
  
  ActiveDocument.Range.Font.Hidden = False
  sText = InputBox("What text are you searching for?")
  
  For Each aTbl In ActiveDocument.Tables
    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 Each aRow In aTbl.Rows
        If Not InStr(aRow.Range.Text, sText) > 0 Then
          aRow.Range.Font.Hidden = True
        Else
          Set aCell = aRow.Cells(aRow.Cells.Count)
          sRefs = sRefs & "|" & Split(aCell.Range.Text, vbCr)(0)   'builds a list of all the wanted refs
        End If
      Next aRow
      Set aRng = Nothing
    Else
      If Not aRng Is Nothing Then 'hide both tables
        aRng.End = aTbl.Range.End
        aRng.Font.Hidden = True
        Set aRng = Nothing
      End If
    End If
  Next aTbl
  With ActiveDocument.Tables(ActiveDocument.Tables.Count)
    Debug.Print sRefs
    For Each aRow In .Rows
      sTag = Split(aRow.Cells(1).Range.Text, vbCr)(0)
      'Debug.Print sTag
      aRow.Range.Font.Hidden = Not InStr(sRefs, sTag) > 0
    Next aRow
  End With
  
  With ActiveWindow.View
    .ShowAll = False
    .ShowHiddenText = False
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote