Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-04-2020, 05:42 AM
macropod's Avatar
macropod macropod is offline A way to delete when 2nd column is empty Windows 7 64bit A way to delete when 2nd column is empty Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Deleting empty table rows is far simpler than what you're using. For example:
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
      With .Rows(r)
        If Len(.Range.Text) = .Cells.Count * 2 + 2 Then .Delete
      End With
    Next
  End With
Next
Application.ScreenUpdating = True
End Sub
To delete a row if a cell in a specified column (in this case column 2) is blank:
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
      With .Rows(r)
        If Len(.Cells(2).Range.Text) = 2 Then .Delete
      End With
    Next
  End With
Next
Application.ScreenUpdating = True
End Sub
PS: When posting code, please structure your code properly and use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
A way to delete when 2nd column is empty Why i can not delete empty row in table? jaryszek Word Tables 2 06-28-2019 04:19 AM
Need to delete duplicate of a column B based on column A and keep ColumnB if unique value to columnA enigmaprince OneNote 0 08-23-2017 01:30 PM
A way to delete when 2nd column is empty Delete Empty Table Rows cltay87 Word VBA 4 02-27-2017 04:23 AM
A way to delete when 2nd column is empty Delete row with empty cel in a table vibor Word VBA 9 05-03-2015 05:42 AM
Creating VBA Code to Delete Empty Column in Table Faugs Word VBA 5 08-07-2014 03:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:06 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