Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-12-2020, 12:14 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 Search in Nested Tables to Delete Rows

I often received large documents with many, many tables. Most of the tables contain another table (i.e., nested table). I need to search only the nested tables for rows containing certain text. If that text is found, I need to delete that row. Unfortunately, the text may also appear in the main table. I tried to write code (provided below) to do this; but it does not work. Given my VBA skillset, that is no surprise. I am hoping one of the experts, here, would take a look at it and point out the errors.

I have attached an example of the files that I receive. The main tables can be several rows and contain one or more nested tables plus text.



Code:
Sub SearchNestedTables()

'Search nested table rows for text and delete those rows
'My code does not work

Application.ScreenUpdating = False

    Dim MainTable As Table
    Dim NestedTable As Table
 
    For Each MainTable In ActiveDocument.Tables
        For Each NestedTable In MainTable.Tables
    With ActiveDocument.Range
        With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "XXX text"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchWildcards = True
            .Execute
        End With
        Do
            If .Information(wdWithInTable) = True Then
                With NestedTable.Rows.Range
                .Rows(1).Delete
                End With
            End If
            .Collapse wdCollapseEnd
        Loop While .Find.Execute
    End With
        Next NestedTable
     Next MainTable 
Application.ScreenUpdating = True
MsgBox "Done!", vbInformation
End Sub
Attached Files
File Type: docx NestedTablesTest.docx (25.8 KB, 9 views)
Reply With Quote
 

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 06:14 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