Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2017, 11:41 AM
nasserlouis nasserlouis is offline problem with deleting empty rows MS Word VBA Windows 7 32bit problem with deleting empty rows MS Word VBA Office 2007
Novice
problem with deleting empty rows MS Word VBA
 
Join Date: Aug 2017
Posts: 6
nasserlouis is on a distinguished road
Default problem with deleting empty rows MS Word VBA

Hello;
I have this microsoft Word file i need to :

1_ delete empty rows with this macro
------------------


Code:
 
Sub DeleteBlankTableRows()

Dim deleted As Boolean
Dim oRow As Row

deleted = False

On Error Resume Next
ActiveDocument.Tables(1).Select
If Selection.Information(wdWithInTable) = False Then
    MsgBox "No table exists in the document!", vbCritical, "Error"
    Exit Sub
End If

For Each oRow In Selection.Tables(1).Rows
    If oRow Is Nothing Then
        MsgBox "The tool cannot work in this table. This might be because one or more rows have merged cells. If these merged cells are removed, it will probably work.", _
        vbCritical, "Error"
        End
    End If
     If Len(oRow.Cells(2).Range.Text) = 2 Then
   'Or If InStr(oRow.Range.Text, "") > 0 Then
        oRow.Delete
        deleted = True
    End If
Next oRow

If deleted Then
    MsgBox "All Blank lines have been deleted.", vbOKOnly, "Success!"
Else
    MsgBox "No Blank lines containing *To Be Deleted* text can be found.", vbOKOnly, "Failure!"
End If

End Sub
-------------------------
the problem is the macro code delete those (see the picture) rows that i don't want to be deleted



2_ i want to use that macro to delete empty rows for all 100 tables with the same construction.

Thank you
Attached Images
File Type: png vbaProblem.png (58.8 KB, 22 views)
Attached Files
File Type: docx onetable.docx (26.0 KB, 21 views)

Last edited by nasserlouis; 08-17-2017 at 04:13 PM. Reason: solved
Reply With Quote
  #2  
Old 08-17-2017, 02:55 PM
macropod's Avatar
macropod macropod is offline problem with deleting empty rows MS Word VBA Windows 7 64bit problem with deleting empty rows MS Word VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub DeleteEmptyRows()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long
For Each Tbl In ActiveDocument.Tables
  With Tbl
    For r = .Rows.Count To 1 Step -1
      If .Rows(r).Cells.Count > 1 Then
        If Len(.Cell(r, 2).Range.Text) = 2 Then .Rows(r).Delete
      End If
    Next
  End With
Next
Application.ScreenUpdating = True
End Sub
Note: As coded, the macro processes all tables in the document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-17-2017, 04:00 PM
nasserlouis nasserlouis is offline problem with deleting empty rows MS Word VBA Windows 7 32bit problem with deleting empty rows MS Word VBA Office 2007
Novice
problem with deleting empty rows MS Word VBA
 
Join Date: Aug 2017
Posts: 6
nasserlouis is on a distinguished road
Default

Hi;
your suggestion code it worked a treat, many thanks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula for deleting empty text boxes lenzz920 PowerPoint 0 08-14-2017 01:02 AM
problem with deleting empty rows MS Word VBA Delete Empty Table Rows cltay87 Word VBA 4 02-27-2017 04:23 AM
Copying specific columns of a table to WORD and deleting rows ffinley Word VBA 5 12-07-2015 04:01 PM
problem with deleting empty rows MS Word VBA Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM
Deleting empty lines lostsoul62 Word 5 04-16-2012 04:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft