Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2018, 10:07 AM
Formd Formd is offline Remove blank table rows AFTER mailmerge Windows 7 32bit Remove blank table rows AFTER mailmerge Office 2007
Advanced Beginner
Remove blank table rows AFTER mailmerge
 
Join Date: Feb 2015
Location: TX
Posts: 46
Formd is on a distinguished road
Default Remove blank table rows AFTER mailmerge


In MSWord 2016, I have a mailmerge document that has a table with mergefields to insert defendants names and addresses. I use the If statement to leave the rows blank if the defendant is deceased. How do I set up a macro to run "after" the merge to search for and delete those rows left blank?
Reply With Quote
  #2  
Old 05-09-2018, 02:41 PM
macropod's Avatar
macropod macropod is offline Remove blank table rows AFTER mailmerge Windows 7 64bit Remove blank table rows AFTER mailmerge 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

Depending on how your data are structured, you could use a DATABASE field in the mailmerge main document to do the table creation.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-10-2018, 01:33 PM
Formd Formd is offline Remove blank table rows AFTER mailmerge Windows 7 32bit Remove blank table rows AFTER mailmerge Office 2007
Advanced Beginner
Remove blank table rows AFTER mailmerge
 
Join Date: Feb 2015
Location: TX
Posts: 46
Formd is on a distinguished road
Default

Not sure how to do the DATABASE field to do the table creation. That sounds like a better option than the macro. I would love to try that. Can you elaborate on that? I included an attachment so you can see how my form is outlined.

I also tried this code that I found online. Except it gave me an error message that read: "Run-time error 5991
Cannot access individual rows in this collection because the table has vertically merged cells". Any ideas?



Sub ActiveTableDeleteEmptyCells()
Dim oTable As Word.Table
Dim oCell As Word.Cell
Dim iCell As Integer
Dim iRow As Integer
Dim iCol As Integer
Application.ScreenUpdating = False
Set oTable = ActiveDocument.Bookmarks("Deftab").Range.Tables(1)
iCell = ActiveDocument.Bookmarks("Deftab").Range.Cells(1). Row.Index
With oTable
For iRow = .Rows.Count To iCell Step -1
For iCol = 1 To .Columns.Count
Set oCell = .Cell(iRow, iCol)
If Len(Trim(oCell.Range.Text)) = 2 Then
oCell.Delete Shiftcells:=wdDeleteCellsShiftUp
End If
Next
Next
End With
Set oCell = Nothing
Set oTable = Nothing
End Sub
Attached Files
File Type: doc Sample_Delrow.doc (132.0 KB, 22 views)
Reply With Quote
  #4  
Old 05-10-2018, 02:04 PM
macropod's Avatar
macropod macropod is offline Remove blank table rows AFTER mailmerge Windows 7 64bit Remove blank table rows AFTER mailmerge 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

For a demonstration of the DATABASE field being used for a mailmerge, see: https://www.msofficeforums.com/mail-...-multiple.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-11-2018, 06:50 AM
Formd Formd is offline Remove blank table rows AFTER mailmerge Windows 7 32bit Remove blank table rows AFTER mailmerge Office 2007
Advanced Beginner
Remove blank table rows AFTER mailmerge
 
Join Date: Feb 2015
Location: TX
Posts: 46
Formd is on a distinguished road
Default

Thanks Paul
I saw the attachment you recommended prior to asking for help in this forum but that didn't help me. so here I am.
My concern is cleaning up the table after the merge because most of the times users have blank rows in the table after merging. Running a macro to do that would be my answer but initiating that macro after the merge without user having to click a button, is what I am having a problem with.

Last edited by Formd; 05-11-2018 at 06:51 AM. Reason: spell check
Reply With Quote
  #6  
Old 05-11-2018, 03:43 PM
macropod's Avatar
macropod macropod is offline Remove blank table rows AFTER mailmerge Windows 7 64bit Remove blank table rows AFTER mailmerge 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

A macro to delete rows would not be straight-forward because you have vertically-merged (aka horizontally-split) cells. The simplest way of handling this would be to use IF fields so you only output tables with the number of rows that are required. See attached.
Attached Files
File Type: doc Demo.doc (170.5 KB, 125 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Blank Space between table heading and table rows Pete Jones Word Tables 5 01-22-2018 04:11 PM
Remove blank table rows AFTER mailmerge How to remove blank spaces between rows in a table, Jamal NUMAN Word 2 04-28-2017 12:59 PM
Remove any pivot table fields with a blank entry Ramtrap Excel Programming 0 04-14-2017 07:00 AM
how to remove blank box on top-left corner of table in PPT 2010? dylansmith PowerPoint 3 10-18-2012 03:59 AM
Remove blank table rows AFTER mailmerge How to remove blank rows from a specified range? Learner7 Excel 1 04-19-2011 02:45 AM

Other Forums: Access Forums

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