Word macro to delete identical rows in a doc
Closed
dmr316
Posts
4
Registration date
Thursday July 23, 2009
Status
Member
Last seen
July 24, 2009
-
Jul 24, 2009 at 05:47 AM
VTTP - Mar 1, 2010 at 11:40 AM
VTTP - Mar 1, 2010 at 11:40 AM
Related:
- Word macro to delete identical rows in a doc
- Word apk for pc - Download - Word processors
- How to delete a row in a table in word - Guide
- Number to text in word - Guide
- Number to word in excel - Guide
- How to download a google doc with comments - Guide
2 responses
dmr316
Posts
4
Registration date
Thursday July 23, 2009
Status
Member
Last seen
July 24, 2009
Jul 24, 2009 at 10:07 AM
Jul 24, 2009 at 10:07 AM
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.
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.
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
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