Step 5 - Real World Examples

Delete All Rows of a Table that Contain a Particular Text String in the First Column

(By Word MVP Bill Coan)

Sub DeleteRows() 

Dim TargetText As String
Dim oRow As Row
If Selection.Information(wdWithInTable) = False Then Exit Sub
TargetText = InputBox$("Enter target text:", "Delete Rows")
For Each oRow In Selection.Tables(1).Rows
If oRow.Cells(1).Range.Text = TargetText & vbCr & Chr(7) Then oRow.Delete

Next oRow
End Sub

Delete All Empty Rows in a Table

(By Word MVPs Dave Rado and Ibby)

Public Sub DeleteEmptyRows()
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.
Set oTable = Selection.Tables(1)

' Set a range variable to the first row's range
Set oRow = oTable.Rows(1).Range
NumRows = oTable.Rows.Count
Application.ScreenUpdating = False

For Counter = 1 To NumRows
StatusBar = "Row " & Counter
TextInRow = False

For Each oCell In oRow.Rows(1).Cells
If Len(oCell.Range.Text) > 2 Then
'end of cell marker is actually 2 characters
TextInRow = True
Exit For
End If
Next oCell

If TextInRow Then
Set oRow = oRow.Next(wdRow)
End If

Next Counter

Application.ScreenUpdating = True

End Sub

Delete Empty TextBoxes in a Presentation

Sub RemoveEmptyTextBoxes()
Dim SlideObj As Slide
Dim ShapeObj As Shape
Dim ShapeIndex As Integer
For Each SlideObj In ActivePresentation.Slides
For ShapeIndex = SlideObj.Shapes.Count To 1 Step -1
Set ShapeObj = SlideObj.Shapes(ShapeIndex)
If ShapeObj.Type = msoTextBox Then
If Trim(ShapeObj.TextFrame.TextRange.Text) = "" Then
End If
End If
Next ShapeIndex
Next SlideObj
End Sub

 Step 1 - Start with the Macro Recorder

Step 2 - Read and Understand the Code

Step 3 - Learn Programming Fundamentals

Step 4 - Share Your Macro with Others

Step 5 - Real World Examples

Share Facebook Facebook Twitter Twitter Email Email

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!