【发布时间】:2022-01-06 19:23:46
【问题描述】:
我有这段代码(附在下面),如果所有单元格行都是空的,它将删除单词表中的行。
但是,我有一个包含八列的表格,其中前四列将始终包含文本。后四个包含链接到 Excel 文档的数据。
问题是;如何让代码搜索后四个(数据)列,如果列为空和/或包含值(例如零),则删除该行。
任何帮助将不胜感激。
提前致谢
Sub DeleteBlankRowsAndTablesInATable()
Dim objCell As Cell
Dim nRowIndex As Integer, nRows As Integer, nColumns As Integer, nColumnIndex As Integer
Dim varCellEmpty As Boolean
Application.ScreenUpdating = False
If Selection.Information(wdWithInTable) = False Then
MsgBox ("Put cursor inside a table first!")
Exit Sub
Else
With Selection.Tables(1)
nRows = .Rows.Count
For nRowIndex = nRows To 1 Step -1
varCellEmpty = True
For Each objCell In .Rows(nRowIndex).Cells
If Len(objCell.Range.Text) > 2 Then
varCellEmpty = False
Exit For
End If
Next objCell
If varCellEmpty = True Then
.Rows(nRowIndex).Delete
End If
Next nRowIndex
End With
End If
Set objCell = Nothing
Application.ScreenUpdating = True
End Sub
【问题讨论】: