![]() |
#1
|
|||
|
|||
![]()
Hi,
I'm looking for a macro that will delete all empty rows from all tables in my word doc. Thanks. |
#2
|
||||
|
||||
![]()
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thanks.
This deletes some empty rows but leaves some. Can it be tweaked to get them all? Thanks. ![]() ![]() ![]() ![]() |
#4
|
||||
|
||||
![]()
Hi brad,
Quote:
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] |
#5
|
|||
|
|||
![]()
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. |
#6
|
||||
|
||||
![]()
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] |
#7
|
|||
|
|||
![]()
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?
|
#8
|
||||
|
||||
![]()
Are these cells in particular columns, or in any column?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
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.
|
#10
|
||||
|
||||
![]()
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] |
#11
|
|||
|
|||
![]()
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? |
#12
|
||||
|
||||
![]()
Do all rows have at least two cells?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
||||
|
||||
![]()
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] |
#14
|
|||
|
|||
![]()
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. |
#15
|
|||
|
|||
![]()
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!!!
|
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
rene.kamphuis@ciz.nl | Mail Merge | 21 | 04-15-2011 12:34 AM |
![]() |
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 |
![]() |
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 |