Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-12-2020, 12:33 PM
gmaxey gmaxey is offline Search in Nested Tables to Delete Rows Windows 10 Search in Nested Tables to Delete Rows Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default


I found and adapted this which may work for you:

Code:
Sub QuerryAllTables()
Dim oTbl As Table
Dim oRng As Range
  For Each oTbl In fcnCollectDocTables
    'MsgBox "Cell count: " & oTbl.Range.Cells.Count & " - Nesting level:" & oTbl.NestingLevel
    If oTbl.NestingLevel > 1 Then
      Set oRng = oTbl.Range
      With oRng.Find
        .Text = "XXX text"
        Do While .Execute
         If oRng.InRange(oTbl.Range) Then
           oRng.Rows(1).Delete
         Else
           Exit Do
         End If
        Loop
      End With
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub

Function fcnCollectDocTables(Optional ByVal oDoc As Document) As Collection
'Returns all tables (top level and nested) in one collection.
Dim colStack As New Collection
Dim oTbl As Table
  Set fcnCollectDocTables = New Collection
  If Documents.Count > 0 And oDoc Is Nothing Then
    Set oDoc = ActiveDocument
  Else
    GoTo lbl_Exit
  End If
  colStack.Add oDoc.Tables
  Do While colStack.Count > 0
    For Each oTbl In colStack(1)
      fcnCollectDocTables.Add oTbl
      If oTbl.Tables.Count > 0 Then colStack.Add oTbl.Tables
    Next
    colStack.Remove 1
  Loop
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 11-12-2020, 12:38 PM
JingleBelle JingleBelle is offline Search in Nested Tables to Delete Rows Windows 10 Search in Nested Tables to Delete Rows Office 2016
Novice
Search in Nested Tables to Delete Rows
 
Join Date: Nov 2020
Posts: 26
JingleBelle is on a distinguished road
Default

Thank you! I will give this a whirl. I appreciate the help (well, actually, the complete rewrite).
Reply With Quote
Reply

Tags
nested table, search nested table



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Nested Tables LBruce Word VBA 3 01-20-2020 09:07 AM
Search in Nested Tables to Delete Rows Delete all empty rows in all tables fbucaram Word VBA 6 01-05-2018 03:04 PM
Nested tables. Count rows NevilleT Word VBA 9 05-10-2017 05:22 AM
Search in Nested Tables to Delete Rows Macro to delete all empty rows from all tables braddgood Word VBA 15 10-02-2015 01:54 PM
Nested vlookup with varable tables! Dave Jones Excel 0 08-30-2012 09:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:30 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