1
votes

I been struggling with a word macro that deletes Empty lines where a "$" exists. The code below works but only for the selected table, how can I have the code loop through the entire document and delete empty lines from all pages.

Document

Option Explicit

Sub TEST()
Dim i       As Long
    With Selection.Tables(1)
        For i = .Rows.Count To 1 Step -1
            If Len(.Cell(i, 2).Range.Text) = 3 And Left(.Cell(i, 2).Range.Text, 1) = "$" Then
                .Rows(i).Delete
            End If
        Next i
    End With
End Sub
1
Are only looking into tables in each worksheet?M--
Yes, But doesn't have to be table as long as it deletes any empty line where a dollar sign exist.user7675421

1 Answers

3
votes

This is not tested on the same data-set as OP has since it is not provided.

Option Explicit

Sub TEST() 


Dim tbl As Table
Dim mDoc As Document
Dim oRow As Row

Set mDoc = ActiveDocument


    For Each tbl in mDoc.Tables

        For Each oRow In tbl.Rows

                 If Len(oRow.Cells(2).Range.Text) = 3 And _
                    Left(oRow.Cells(2).Range.Text, 1) = "$" Then 

                        oRow.Delete 

                 End If 
              Next oRow 
    Next tbl

End Sub