PDA

View Full Version : Word Table - Delete Rows where Cell Values all = 0



ajhez
05-03-2017, 11:21 AM
Hi all

I have a document with a large table that will be populated with information as per the example below.




Type 1
Type 2
Type 3
Type 4


Matter 1
0%
2%
3%
1%


Matter 2
0%
0%
0%
0%


Matter 3
1%
0%
4%
0%



I need a macro to recognize when all 4 cells in a row have a 0% value and then delete those rows -e.g. 'Matter 2' in the above example. For the avoidance of doubt, other rows can remain where one ore more cells in that row has a value of 0% provided that not all 4 cells in that row are 0%.

Any thoughts would be great.

Thanks,
AJHEZ

gmaxey
05-03-2017, 01:16 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim lngIndex As Long, lngCell As Long
Dim bKill As Boolean
Set oTbl = Selection.Tables(1)
For lngIndex = oTbl.Rows.Count To 2 Step -1
bKill = True
For lngCell = 2 To 5
If Left(oTbl.Cell(lngIndex, lngCell).Range.Text, 2) <> "0%" Then
bKill = False
Exit For
End If
If bKill Then oTbl.Rows(lngIndex).Delete
Next lngCell
Next lngIndex
lbl_Exit:
Exit Sub
End Sub