Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2021, 11:32 AM
nmkhan3010 nmkhan3010 is offline Table deletions based on a string. Windows 10 Table deletions based on a string. Office 2016
Novice
Table deletions based on a string.
 
Join Date: Feb 2020
Posts: 23
nmkhan3010 is on a distinguished road
Default Table deletions based on a string.

Table deletions based on a string.

If a string “AAA” is available in the any table in any cell, then delete all the above tables excluding from “AAA” found table and all the below tables.

Doc format: ".docx"

Suppose they are 1 to 50 tables in a document, AAA found in table 25 then delete all the tables from 1 to table 24.

Purpose is to delete the unnecessary tables base on that strings…

Please help me in this regards and thanks in advance.

Please find a attachment.
Attached Files
File Type: docx Table deletions based on a string.docx (54.8 KB, 5 views)
Reply With Quote
  #2  
Old 05-03-2021, 01:26 PM
macropod's Avatar
macropod macropod is offline Table deletions based on a string. Windows 10 Table deletions based on a string. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For example:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "AAA"
    .Replacement.Text = ""
    .Format = False
    .Forward = False
    .Wrap = wdFindStop
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
  End With
  Do While .Find.Execute
    If .Information(wdWithInTable) = True Then
      Set Rng = ActiveDocument.Range(0, .Tables(1).Range.Start)
      Do While Rng.Tables.Count > 0
        Rng.Tables(1).Delete
      Loop
      Exit Do
    End If
    .Collapse wdCollapseStart
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-03-2021, 08:52 PM
nmkhan3010 nmkhan3010 is offline Table deletions based on a string. Windows 10 Table deletions based on a string. Office 2016
Novice
Table deletions based on a string.
 
Join Date: Feb 2020
Posts: 23
nmkhan3010 is on a distinguished road
Default Deleting the above and below tables

Thank you so much its working great and highly appreciated for your work.

Adding another query related to the same task...

Like wise is it possible to delete the above and below the tables based on a matched strings in a table.

Example: In a document having 100 tables; if match string is available in table 20 then delete all the above tables from table 1 to table 19 & another match string is available in table 50 then delete all the below tables from 51 to table 100. then document will have only the relevant tables from table 20 to table 50 & we had deleted the unnecessary tables manually, can we automate this task, please suggest me ...

Thanks in advance.....
Attached Files
File Type: docx Table deletions based on above and below strings.docx (56.4 KB, 5 views)
Reply With Quote
  #4  
Old 05-03-2021, 08:57 PM
macropod's Avatar
macropod macropod is offline Table deletions based on a string. Windows 10 Table deletions based on a string. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

How about a little effort on your part. The code I posted already gives you the clues for how to do that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
table deletions

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Table deletions based on a string. Track Changes Problem - lines from comments & deletions don't go to right text. Emmryss Word 6 01-17-2019 05:37 PM
VBA to provide text string with specific formating based on Drop down list (content control) MP1989 Word VBA 4 07-30-2018 02:40 AM
Table deletions based on a string. Stop Show Up Formatting and Insertions&Deletions theta30 Word 6 03-20-2014 03:57 PM
Macro to format additions deletions when Comparing Files Alphacsulb Word VBA 0 08-19-2013 03:03 PM
inserting a string of data into an MS Word table??? matto Word VBA 0 07-16-2010 09:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:52 PM.


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