Ask your question

Word macro to delete identical rows in a doc

dmr316 2Posts July 23, 2009Registration date - Jul 24, 2009 10:47am BST - Last answer on Mar 1, 2010 4:40pm GMT VTTP
Hello everyone, I hope someone is able to help me. Every day I work with an RTF export from non-Microsoft software, which is a Word-like document set out with multiple tables in the style of 2 "newspaper columns" per page. I would open this file in Word 2003.

Unfortunately, a lot of the table rows are redundant (see below description) and it would be really convenient if there was a quick way to delete them all, seeing as these RTF exports can go on for about a hundred pages (which is why I decided not to delete them all by hand).

The rows that need to be deleted are of the form: Blank cell, Blank cell, Blank cell with a tab in it, Cell containing three characters: a space, then a zero, then another space. i.e. with the backwards-P symbol on it's [][][tab arrow][sp 0 sp]

On my first try at macros, I was able to delete just one row like that. However, it won't delete any other rows like that. And finally, because I've got multiple tables all with the same problem, I would dearly like to be able to delete those rows in other, separate, tables in that same document.

Thank you in advance for any help.Configuration: Windows XP SP3, Internet Explorer 8.0, Microsoft Office 2003
Add comment

« Word macro to delete identical rows in a doc »

Macro for deleting row with conditionForumOffice software
Excel Macro for deleting rows IF cells not... [Solved]ForumOffice software
Excel blank row deletionForumOffice software
Copy paste and delete rows based on a criteriForumProgramming
To highlight duplicate rows with some colourForumOffice software
Excel VBA to filter rows containing same wordForumOffice software
Sort by :   Votes | Date | Date descending 2 answers
Best answer
+3
moins plus
I have found some macros on the internet which may help:

This macro finds each table in turn:
Sub FindTables()
Dim iResponse As Integer
Dim tTable As Table
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
tTable.Select
iResponse = MsgBox("Table found. Find next?", 68)
If response = vbNo Then Exit For 'User chose to leave search.
Next
MsgBox prompt:="Search Complete.", buttons:=vbInformation
End Sub

This macro deletes any rows with a blank cell in the first column:
Sub DeleteRows()
Dim TargetText As String
Dim oRow As Row
If Selection.Information(wdWithInTable) = False Then Exit Sub
TargetText = InputBox$("Enter target text:", "Delete Rows")
For Each oRow In Selection.Tables(1).Rows
If oRow.Cells(1).Range.Text = TargetText & vbCr & Chr(7) Then oRow.Delete
Next oRow
End Sub

If anyone could modify the second macro to delete any rows with a blank cell in the third column and then nest it within the first macro to enable multiple tables to be amended, I'm sure that would solve my problem. I wish I was better at VBA to be able to do this for myself.

Thanks in advance if anyone can combine those for me with that slight change to the second macro.
Add comment
+0
moins plus
Sub FindTables()
Dim iResponse As Integer
Dim tTable As Table
Dim TargetText As String
Dim oRow As Row

TargetText = InputBox("Enter target text:", "Delete Rows") 'Place this code between the lines with the For
Each statement to enter different target text for different tables

For Each tTable In ActiveDocument.Tables
For Each oRow In tTable.Rows
If oRow.Cells(2).Range.Text = TargetText & vbCr & Chr(7) Then oRow.Delete
Next oRow
Next tTable

End Sub
Add comment