PDA

View Full Version : VBA To Remove Rows From Table



bilbo85
09-21-2016, 04:32 PM
Hi,

Wonder if someone could help at all please?

I'm after some VBA code to use in Word that will look in any USER HIGHLIGHTED table, will look in the 2nd column and if it says "Error", it will delete the entire row from the table. It will then loop through and delete each row as appropriate.

Any ideas please?

Thanks so much!

gmaxey
09-21-2016, 05:38 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngIndex As Long
With Selection.Tables(1)
For lngIndex = .Rows.Count To 1 Step -1
If Left(.Cell(lngIndex, 2).Range.Text, Len(.Cell(lngIndex, 2).Range.Text) - 2) = "Error" Then
.Rows(lngIndex).Delete
End If
Next
End With
lbl_Exit:
Exit Sub
End Sub