![]() |
#1
|
|||
|
|||
![]()
HI All,
I am trying to create a mail merge that shows details of share awards of 3 years (2 Awards in each year). For ease i want to keep the template standard as this will be used year after year and data just updated over/written. The problem i have is that not all recipients of an award this year (the start point) received awards in previosu years, meaning some have multiple lines of blank data. I have uploaded my dummy data which shows no award for the DBP in 2018, but thsi may occur in the other tables above to...any help is appreciated |
#2
|
||||
|
||||
![]()
The only ways around this are to:
• have a different version of each table for the options that may or may not occur and use IF tests to determine which version of the table to output in each case; or • use a macro to clean up the output post-merge.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
I was hoping for the latter but have no idea where to start..
|
#4
|
||||
|
||||
![]()
You could add the following macro to your mailmerge main document. When you click on Finish & Merge>Edit Individual Documents, the macro will automatically delete all table rows where the last cell on a given row is empty.
Code:
Sub MailMergeToDoc() Application.ScreenUpdating = False Dim Tbl As Table, r As Long, c As Long ActiveDocument.MailMerge.Execute With ActiveDocument For Each Tbl In .Tables With Tbl c = .Columns.Count For r = .Rows.Count To 2 Step -1 If Split(.Cell(r, c).Range.Text, vbCr) = 0 Then .Rows(r).Delete Next End With Next End With Application.ScreenUpdating = False End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
i have ran it but it has deleted all the data out of the workbooks. I am guessing there are multiple tables with multiple blank lines in my book (i made it in excel and then pasted to Word)
|
#6
|
||||
|
||||
![]()
It's a Word macro that has no effect on any workbooks - only on tables in the mailmerge output document and, even then, only on rows in which the last cell is empty, but always leaving the header row alone.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
Sorry i meant the data pulled from my workbooks. the output document is one giant table (I think) as i created it in excel and then pasted to word)
|
#8
|
||||
|
||||
![]()
Perhaps you could attach your mailmerge main document and a sample output document to a post with some representative data (delete anything sensitive)? You can do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Hi Following on from my last post.
MacroPod has asked for the attached to hopefully be able to help out. I have removed a cover page from the first page that gave away the company! I have made up most of the data but the concept will be the same and there is about 74 people in the merge |
#10
|
||||
|
||||
![]()
The reason the macro has trouble with your document is that the content is not in separate tables and you have many rows whose last cell is empty and that has nothing to do with the rows you want to delete. Moreover, you table has vertically merged cells, which means it's impossible to process it in the normal manner. None of that was apparent from your screenshot.
Try the following revision to the macro: Code:
Sub MailMergeToDoc() Application.ScreenUpdating = False Dim Tbl As Table, r As Long, c As Long ActiveDocument.MailMerge.Execute For Each Tbl In ActiveDocument.Tables With Tbl If .Range.Cells(.Range.Cells.Count).RowIndex = 50 Then For r = 43 To 30 Step -1 Select Case r Case 30, 31, 36, 37, 42, 43 If Split(.Cell(r, 4).Range.Text, vbCr)(0) = "" Then For c = 4 To 1 Step -1 .Cell(r, c).Delete Next End If End Select Next End If End With Next Application.ScreenUpdating = False End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
![]()
Thank you so much for your help (and apologies for being really poor at explaining myself).
I have been asked to slightly change the format by adding in another line underneath the DBP award line. can the code easitly be amended to reflect this? |
#12
|
||||
|
||||
![]()
Yes - you simply need to update the total row count that is used to identify the table (i.e. RowIndex = 50) and the individual row references for the rows you might want to delete (i.e. Case 30, 31, 36, 37, 42, 43).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
![]()
...for the dumb one in the thread....i take it i highlight the workbook to the row i want, go into table properties and start the counts from there?
|
#14
|
|||
|
|||
![]()
I have had a stab but its not worked (It worked the first time around so thank you).
|
#15
|
||||
|
||||
![]()
Clearly, you'd increase the RowIndex value by the number of rows you're adding to the table.
As for the Case values, that likewise depends on which of the DBP award lines (you have 3) you're adding the new line below. If it's all 3, you might use: Case 30, 31, 32, 37, 38, 39, 44, 45, 46
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to delete every blank and non-numeric rows without removing the header | enuff | Excel | 3 | 08-24-2017 05:56 AM |
Removing blank pages at the end of a document | Xanzia | Word | 3 | 06-01-2014 11:13 AM |
![]() |
Welshie82 | Mail Merge | 2 | 11-14-2011 01:41 AM |
Urgent help needed with removing blank lines... | iammom2four | Outlook | 0 | 12-15-2010 06:12 AM |
![]() |
sieler | Word | 3 | 04-12-2009 01:38 PM |