|
本帖最后由 batmanbbs 于 2023-6-1 13:53 编辑
- Sub 删除表格空行()
- '
- '删除表格中除了第一列之外都是空白单元格的行
- '
- Dim myTB As Table
- Dim i%, iRow%, iCol%, rStart&, rEnd&
- Dim isDel As Boolean
- If Selection.Tables.Count = 0 Then
- MsgBox "没有指定表格"
- Else
- isDel = False
- Set myTB = Selection.Tables(1)
- With myTB
- iRow = .Rows.Count
- iCol = .Columns.Count
- For i = iRow To 2 Step -1 '跳过表头第一行
- rStart = .Cell(i, 2).Range.Start
- rEnd = .Cell(i, iCol).Range.End
- Text = ActiveDocument.Range(rStart, rEnd)
- Text = Trim(Replace(Replace(Text, Chr(13), ""), Chr(7), ""))
- If Len(Text) = 0 Then
- If i = iRow Then
- Text = .Cell(i, 1).Range
- Text = Trim(Replace(Replace(Replace(Text, " ", ""), Chr(13), ""), Chr(7), ""))
- If Text Like "[总合小]计" Then isDel = True: Exit For
- End If
- .Cell(i, 2).Select
- With Selection
- .SelectRow: .Rows.Delete
- End With
- End If
- Next i
- End With
- If isDel Then
- myTB.Delete
- With Selection
- .MoveUp: .Paragraphs(1).Range.Delete
- End With
- End If
- End If
-
- Set myTB = Nothing
- End Sub
复制代码 |
|