#1
|
|||
|
|||
I need to remove rows in a table where the Merge field is empty
In the attached Word document I have a table, where information is being pulled by merge fields from Excel.
When I hit Finish & Merge, I would like to have any rows (shaded in the example) removed but leave the formula cell (total amount) intact. Some company's may have 1 in the SS section, and others will have 10. I have set the table to show 10, but if a company has less than that I would like the lines removed so that there is less white space when I send them a copy. Please let me know if there is a macro I can add to my master template, that will allow the Finish & Merge to remove blank lines but leave the blank lines between the sections. |
#2
|
||||
|
||||
I suspect I might conditionally merge those fields that could be empty to add unique text instead e.g.
{ IF { MERGEFIELD SS_1 } = "" "BLANK" "{ MERGEFIELD SS_1 }" } etc., then run a macro to remove the rows that contain 'BLANK' in the first column e.g. If you use https://www.gmayor.com/email_merge_addin.html to merge the documents, you can run the following macro from the process to remove the blanks on the fly. Code:
Sub DelBlanks(oDoc As Document) Dim oTable As Table Dim iRow As Integer Dim oCell As Range Set oTable = oDoc.Tables(1) For iRow = oTable.Rows.Count - 21 To 5 Step -1 Set oCell = oTable.Cell(iRow, 1).Range oCell.End = oCell.End - 1 If oCell.Text = "BLANK" Then oTable.Rows(iRow).Delete Next iRow End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
See, for example:
https://www.msofficeforums.com/136079-post25.html https://www.msofficeforums.com/147013-post2.html https://www.msofficeforums.com/129119-post4.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mail Merge Template - remove blank rows in a table | Litmus | Mail Merge | 16 | 03-23-2022 01:42 PM |
Macro that deletes all empty rows in selected table | MathiasFC | Word VBA | 2 | 02-10-2019 04:06 PM |
Mail merge: remove empty rows when a field is not showed | Yarikh | Mail Merge | 4 | 09-23-2018 12:17 AM |
Delete Empty Table Rows | cltay87 | Word VBA | 4 | 02-27-2017 04:23 AM |
Mail Merge Empty Data Field | Licos101 | Mail Merge | 2 | 04-10-2014 06:19 AM |