Loading
Word.Tips.Net WordTips (Menu Interface)

Finding and Deleting Rows

Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Finding and Deleting Rows.

Sam has a document that contains some tables in which he wants to delete some rows. The rows contain specific text, which he can certainly delete by using Find and Replace, but he wants to delete the entire rows that contain that text.

There is no way to do this (delete rows) using the normal Find and Replace features of Word. Instead, you need to use a macro that will find the text and then delete the entire row. Here is a relatively simple macro that will do the job:

Sub DeleteRowWithSpecifiedText()
    Dim sText As String

    sText = InputBox("Enter text for Row to be deleted")
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = sText
        .Wrap = wdFindContinue
    End With
    Do While Selection.Find.Execute
        If Selection.Information(wdWithInTable) Then
            Selection.Rows.Delete
        End If
    Loop
End Sub

This macro first displays an input box that asks the user to specify the text to be searched for. It then starts searching for all instances of that text. If an instance is found, then the selection is checked to make sure it is within a table. If it is, then the entire row is deleted and the macro moves on to the next occurrence.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3838) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Finding and Deleting Rows.

Related Tips:

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Amandeep Singh    22 Aug 2016, 07:01
Great Job!!! Saved Alots minutes.. Thanks alot
Nanda Kumar    07 Aug 2016, 06:03
Excellent.
I was searching for this code since long time. Thank you Mr. Allen Wyatt.
Theresa    11 Jul 2016, 10:10
Monday, July 11, 2016

I am looking for a "one-step" MACRO or MODULE process for a 1,048-page file which I need to JUST EXTRACT ONLY CERTAIN ROWS of TABLES to be inserted into an EXCEL file. This module is to FIND and then EXTRACT only two rows from ONLY "certain" tables that have the same unique identifiers (where each column and row have the same row title and its TEXTS)...
This file resulted in an MS Word 2013 document with lots of diagrams, graphics, tables, textual paragraphs spread out throughout AFTER I had merged like hundreds of Word documents into this 1 master Word document, thus each beginning section separated by a “page break” is a different document that got merged and each has its own differently titled TOP HEADER which is NOT IN A ROW. I need to pull in each of these header as well as pull only the two rows of the tables with only those unique identifiers and once they’re extracted, they can stay in another new MS WORD document.
I was thinking of using "wildcards" but then how? The length of those texts within each of those 3 rows vary...thus I guess we are looking at using VBA code to find "STRINGS"?? If that's a proper way to call it or look at it.

There are 2 columns on TOP ROW of the table: 1st column is "Verification Case ID: Testing text, testing text" 2nd column is "Verification Case Name: Testing text, testing text"

There’s 1 column to LAST ROW of the table: "Verification Objective: Testing text, testing text"

If you have an email address, I can send you an attached EXAMPLE DOCUMENT to better understand. I know this can be done, I’ve done something similar to this before but lost my macro/module and it's been 15 years since I last did VBA coding for MS WORD. Thank you kindly and in advance for any help you can muster. I need this ASAP if you can. I can be e-mailed at greatcareer4me@yahoo.com
Tiffany    25 Feb 2016, 18:57
Is there a way to run this macro but skip those that have the specified word and delete those that don't?
VeeCee    30 Jan 2016, 09:32
I have Word documents which contains paragraphs. The sentences are in multiple lines in a table form.

Your macro is brilliant with deleting a line containing a text. Is it possible to modify it so that if I give the first and last word of a paragraph, the whole sentence is deleted?

I found a macro which works IF I convert the table to text which, I do not want to do.

Thank you in advance.
ken Endacott    30 Dec 2015, 05:25
The macro can get into an endless loop under some circumstances. The modified macro to avoid this is:

Sub DeleteRowWithSpecifiedText()
    Dim sText As String

    sText = InputBox("Enter text for Row to be deleted")
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = sText
        .Wrap = wdFindContinue
    End With
    Do While Selection.Find.Execute
        If Selection.Range.Text = "" Then Exit Sub
        If Selection.Information(wdWithInTable) Then
            Selection.Rows.Delete
        End If
    Loop
End Sub

VeeCee,
replace the statement:
sText = InputBox("Enter text for Row to be deleted")

with:
sText = "My text to search for"
VeeCee    30 Dec 2015, 03:01
Great.Is it possible to create a macro that does the same job without the input text? Meaning the text is in the macro and it does the job on executing the macro.
Ricardo Cobos    02 Dec 2014, 21:25
thanks for the code but it didn't work for me using MS Word 2010. It Gets about 1/4 the way through my 970 page document then stops working and it never actually deletes a matching row. kind of odd.
Tani    30 Nov 2014, 08:12
please I'm looking for a macro that search the text in the right cell, and replace it in the next left cell, the replacement must be limited only in the next left cell. and the same for the rest of the whole column.
best regards and many thanks
Juha Kuivalainen    29 Jul 2014, 04:57
Yesterday I asked help for such simple problem because i couldn't find the parameter list that I found today. Got it fixed with MatchWholeWord :)
Juha Kuivalainen    28 Jul 2014, 08:39
This helped me quite a lot at my work. I get employee lists that I have to moderate every 3 weeks for our customer.

My only problem was that the macro also picked up a particular short term from one of the names and deleted two "extra" rows. Is it possible to make the macro pick only "whole words" instead of finding the string in any form?
Mike B    19 Mar 2014, 20:00
Thank you very much for this VBA code. This saved me several hours of work today. Much appreciated. :-)

BTW, this code worked for me in Work 2010.
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.