Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delete a row in a Word table if Column 2 is empty

675 views
Skip to first unread message

Chasepes

unread,
May 27, 2010, 5:36:08 PM5/27/10
to
Hi:
Dave Rado posted some nice code for Deleting Empty Rows in a Table in Word
(http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm).

I need to know how to delete a row in a Word table if Column 2 is empty.

Thanks-

Charlie Epes
Buffalo, NY

Doug Robbins - Word MVP

unread,
May 28, 2010, 1:53:17 AM5/28/10
to

Use:

With Selection.Tables(1)
For i = .Rows.Count To 1 Step -1
If Len(.Cell(i, 2).Range.Text) = 2 Then
.Rows(i).Delete
End If
Next i
End With

when the selection is in the table.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Chasepes" <Chas...@discussions.microsoft.com> wrote in message
news:FE2089DE-1D9B-4220...@microsoft.com...

rok.pl...@gmail.com

unread,
Nov 26, 2013, 3:05:23 AM11/26/13
to
Dne petek, 28. maj 2010 07:53:17 UTC+2 je oseba Doug Robbins - Word MVP napisala:
Hi Doug,

I have found your comment on Charlie whish, but for me code is not working when I'm changing original code to work on every table in document.
Would you mind and take a look what is wrong in my code (I get an error just after this line "With Selection.Tables(1)"):

Option Explicit

Public Sub DeleteEmptyColums_TEST()
Dim oTable As Table, oRow As Range, oCell As Cell, Counter As Long, _
NumRows As Long, TextInRow As Boolean
' Specify which table you want to work on.
For Each oTable In ActiveDocument.Tables
' Set a range variable to the first row's range
Set oRow = oTable.Rows(1).Range
NumRows = oTable.Rows.Count
' Next Table
Application.ScreenUpdating = False
For Counter = 1 To NumRows
StatusBar = "Row " & Counter
TextInRow = False

With Selection.Tables(1)
For i = .Rows.Count To 1 Step -1
If Len(.Cell(i, 2).Range.Text) = 2 Then
.Rows(i).Delete
End If
Next i
End With
Next Counter
Next oTable
Application.ScreenUpdating = True
End Sub

0 new messages