#1
|
|||
|
|||
Removing rows when mail merging
I am trying to create labels for students but have all subjects showing. I need to be able to suppress the rows that the pupils do not study. so all blank rows be removed upon merging. Is this possible? Last edited by Richystab; 12-02-2020 at 07:32 AM. Reason: attached files |
#2
|
||||
|
||||
It would be a simple process to create a macro that checks each row. If you use my merge add-in E-Mail Merge Add-in to merge to separate documents, you could use the following macro to remove them on the fly
Code:
Sub ClearEmpty(oDoc As Document) Dim oTable As Table Dim iRow As Integer, iCol As Integer Dim bFound As Boolean With oDoc For Each oTable In oDoc.Tables If oTable.Columns.Count = 5 Then For iRow = oTable.Rows.Count To 2 Step -1 bFound = False For iCol = 2 To oTable.Rows(iRow).Cells.Count If Len(oTable.Rows(iRow).Cells(iCol).Range) > 2 Then bFound = True Exit For End If Next iCol If bFound = False Then oTable.Rows(iRow).Delete DoEvents Next iRow End If Next oTable End With End Sub Code:
Sub Macro1() ClearEmpty ActiveDocument 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
|
||||
|
||||
This thread is a duplicate of a discussion started here: https://www.msofficeforums.com/155991-post12.html, but with relevant detail that was omitted from that discussion.
Try adding the following to the mailmerge main document: Code:
Sub MailMergeToDoc() Application.ScreenUpdating = False Dim Tbl As Table, r As Long, Rng As Range ActiveDocument.MailMerge.Execute With ActiveDocument For Each Tbl In .Tables With Tbl For r = .Rows.Count To 2 Step -1 Set Rng = .Rows(r).Range With Rng .Start = .Cells(2).Range.Start If Len(.Text) = 2 * .Cells.Count + 2 Then .Rows(1).Delete End With Next End With Next End With Application.ScreenUpdating = False End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Quote:
Thankyou. Sorry I'm new to the Forum! |
Tags |
hide rows |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Removing duplicate rows when identical value in a column | ballpoint | Excel | 1 | 01-05-2018 08:54 AM |
how to delete every blank and non-numeric rows without removing the header | enuff | Excel | 3 | 08-24-2017 05:56 AM |
Merging Multiple Rows in Mail Merge Letter | hrhr3 | Mail Merge | 4 | 08-24-2016 07:37 PM |
Merging Rows - HELP please! | MessyJessy | Excel | 7 | 01-14-2015 01:38 AM |
merging rows and creating sub-rows | gib65 | Excel | 2 | 12-09-2011 02:09 PM |