Word macro to delete identical rows in a doc
Closed
dmr316
Posts
4
Registration date
Thursday 23 July 2009
Status
Member
Last seen
24 July 2009
-
24 Jul 2009 à 05:47
VTTP - 1 Mar 2010 à 11:40
VTTP - 1 Mar 2010 à 11:40
Related:
- Word macro to delete identical rows in a doc
- How to delete a row in word - Guide
- Ms word pdf extension - Download - Other
- How to type a checkmark in word - Guide
- Full screen in word - Guide
- Google doc read aloud - Guide
2 responses
dmr316
Posts
4
Registration date
Thursday 23 July 2009
Status
Member
Last seen
24 July 2009
24 Jul 2009 à 10:07
24 Jul 2009 à 10:07
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