Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

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

已查看 674 次
跳至第一个未读帖子

Chasepes

未读,
2010年5月27日 17:36:082010/5/27
收件人
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

未读,
2010年5月28日 01:53:172010/5/28
收件人

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

未读,
2013年11月26日 03:05:232013/11/26
收件人
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 个新帖子