Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-02-2011, 09:34 AM
braddgood braddgood is offline Macro to delete all empty rows from all tables Windows 7 32bit Macro to delete all empty rows from all tables Office 2007
Novice
Macro to delete all empty rows from all tables
 
Join Date: Jun 2011
Posts: 3
braddgood is on a distinguished road
Default Macro to delete all empty rows from all tables

Hi,

I'm looking for a macro that will delete all empty rows from all tables in my word doc.

Thanks.
Reply With Quote
  #2  
Old 06-02-2011, 05:30 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 32bit Macro to delete all empty rows from all tables Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Hi brad,

Try:
Code:
Sub DeleteEmptyCol2TableRows()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      For i = .Rows.Count To 1 Step -1
        If Len(.Rows(i).Range.Text) = .Rows(i).Cells.Count * 2 + 2 Then .Rows(i).Delete
      Next i
    End With
  Next Tbl
End With
Application.ScreenUpdating = True
End Sub
Note: The macro may fail on tables with vertically-merged cells.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-03-2011, 05:45 AM
braddgood braddgood is offline Macro to delete all empty rows from all tables Windows 7 32bit Macro to delete all empty rows from all tables Office 2007
Novice
Macro to delete all empty rows from all tables
 
Join Date: Jun 2011
Posts: 3
braddgood is on a distinguished road
Default

Thanks.

This deletes some empty rows but leaves some. Can it be tweaked to get them all?

Thanks.
Reply With Quote
  #4  
Old 06-03-2011, 02:24 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 32bit Macro to delete all empty rows from all tables Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Hi brad,
Quote:
This deletes some empty rows but leaves some. Can it be tweaked to get them all?
Your premise is wrong and no tweaking is required to delete all empty rows. I suspect you've got either hidden hidden text or non-printing characters such as spaces in the rows that aren't being deleted - in which case, they're not empty.

You could deal with ordinary spaces by changing:
If Len(.Rows(i).Range.Text) = .Rows(i).Cells.Count * 2 + 2 Then .Rows(i).Delete
to:
If Replace(Len(.Rows(i).Range.Text)," ","") = .Rows(i).Cells.Count * 2 + 2 Then .Rows(i).Delete
but even this won't delete rows with just non-breaking spaces, tabs, paragraph breaks, etc.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-13-2011, 12:47 PM
braddgood braddgood is offline Macro to delete all empty rows from all tables Windows 7 32bit Macro to delete all empty rows from all tables Office 2007
Novice
Macro to delete all empty rows from all tables
 
Join Date: Jun 2011
Posts: 3
braddgood is on a distinguished road
Default

I tried the change and it didn't make a difference. So how would I know if I have non-breaking spaces? Or how would I know what I do have in the lines which appear to be blank?

If it is non-breaking spaces are you saying that there is no solution?

Thanks.
Reply With Quote
  #6  
Old 06-13-2011, 05:03 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 32bit Macro to delete all empty rows from all tables Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Hi brad,

For all I know, you might have non-breaking spaces, tabs, paragraph breaks, line breaks or other non-printing characters. There are solutions for every possibility, but I don't propose to keep guessing what the scenario is. You should establish what the errant characters are and, if they're relatively infrequent, delete them manually. Otherwise, say what they are and I'll tell you how to modify the code to deal with those characters. You can easily reveal what the characters are by toggling the formatting display by clicking the ¶ symbol on the Ribbon's Home tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 10-01-2015, 09:22 AM
jj511 jj511 is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2013
Novice
 
Join Date: Oct 2015
Posts: 5
jj511 is on a distinguished road
Default

This code is great! Is there any way to alter it so that it deletes rows where only 1 or 2 of the cells in that row are blank versus all of the cells being blank?
Reply With Quote
  #8  
Old 10-01-2015, 01:56 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Are these cells in particular columns, or in any column?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 10-01-2015, 02:01 PM
jj511 jj511 is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2013
Novice
 
Join Date: Oct 2015
Posts: 5
jj511 is on a distinguished road
Default

In my case, the blank cells are all in column 2, so if that is easier to define, that works for me. However, if it is easy to check all columns, that works too.
Reply With Quote
  #10  
Old 10-01-2015, 02:26 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 DeleteEmptyCol2TableRows()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      For i = .Rows.Count To 1 Step -1
        If Len(.Cell(i, 2).Range.Text) = 2 Then .Rows(i).Delete
      Next i
    End With
  Next Tbl
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 10-01-2015, 02:57 PM
jj511 jj511 is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2013
Novice
 
Join Date: Oct 2015
Posts: 5
jj511 is on a distinguished road
Default

First off, thank you so much for your help!
That gives me an error though at the following line:
If Len(.Cell(i, 2).Range.Text) = 2 Then

Any suggestions?
Reply With Quote
  #12  
Old 10-01-2015, 03:20 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Do all rows have at least two cells?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 10-01-2015, 10:04 PM
macropod's Avatar
macropod macropod is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Cross-posted at: http://www.mrexcel.com/forum/excel-q...ells-word.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 10-02-2015, 06:02 AM
jj511 jj511 is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2013
Novice
 
Join Date: Oct 2015
Posts: 5
jj511 is on a distinguished road
Default

My apologies on the cross-post.
As for the tables, no, the top 4 rows of each table are header/title rows and are only 1 cell each. The remaining rows in each table contain 6 cells each.
Reply With Quote
  #15  
Old 10-02-2015, 07:06 AM
jj511 jj511 is offline Macro to delete all empty rows from all tables Windows 7 64bit Macro to delete all empty rows from all tables Office 2013
Novice
 
Join Date: Oct 2015
Posts: 5
jj511 is on a distinguished road
Default

Paul--I pulled the headers out of the tables and it worked perfectly! That said, what you provided is exactly what I need. Thank you so much for the help!!!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete all empty rows from all tables Empty rules rene.kamphuis@ciz.nl Mail Merge 21 04-15-2011 12:34 AM
Macro to delete all empty rows from all tables Word Macro to search all tables silverspr Word VBA 3 04-02-2011 11:20 PM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM
Macro to delete all empty rows from all tables I need a macro that removes background of many tables masa57 Word VBA 2 05-08-2010 07:34 AM
Automated "Macro" to delete Tags/Anchors field3 Word VBA 0 02-25-2009 02:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:21 AM.


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