Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2024, 02:03 PM
Rundgren Rundgren is offline Deleting specific rows in Mail Merge document based on data in cells Windows 11 Deleting specific rows in Mail Merge document based on data in cells Office 2021
Novice
Deleting specific rows in Mail Merge document based on data in cells
 
Join Date: May 2024
Posts: 1
Rundgren is on a distinguished road
Default Deleting specific rows in Mail Merge document based on data in cells

Hi everyone,

I'm hoping someone can help me with a problem I'm having with a mail merge document. I've created a mail merge document that pulls data from an excel sheet to generate approximately 300 monthly invoices.



What I need help with is writing a macro that after doing the merge it looks at the three highlighted cells (Interest Adjustment/Tax Reserve/Fees) and if they show a balance of $0.00 then the row(s) are deleted.

I'm not very familiar with macros, so I would appreciate any guidance or suggestions on how to achieve this.

Thank you in advance for your help.
Attached Files
File Type: docx Mail Merge-Test-BLANK.docx (26.9 KB, 5 views)
Reply With Quote
  #2  
Old 08-07-2024, 08:03 PM
macropod's Avatar
macropod macropod is offline Deleting specific rows in Mail Merge document based on data in cells Windows 10 Deleting specific rows in Mail Merge document based on data in cells Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
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

You could, for example, add the following macro to your mailmerge main document, then save it in the .docm format before running the mailmerge.
Code:
Sub MailMergeToDoc()
Application.ScreenUpdating = False
Dim t as long, r As Long
ActiveDocument.MailMerge.Execute
With ActiveDocument
  For t = .Tables.Count to 2 Step - 2
    With .Tables(t)
      For r = 5 To 2 Step -1
        Select Case r
          Case 5, 4, 2
            If Split(.Cell(r, 2).Range.Text, vbCr)(0) = "$0.00" Then
                .Rows(r).Delete
              Next
            End If
        End Select
      Next
    End With
  Next
End With
Application.ScreenUpdating = False
End Sub
For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting specific rows in Mail Merge document based on data in cells Mail Merge to create specific number of table rows flackend Mail Merge 4 12-01-2023 02:49 PM
Deleting specific rows in Mail Merge document based on data in cells Mail merge with multiple rows of data ARoude Mail Merge 3 09-10-2018 02:32 PM
Deleting specific rows in Mail Merge document based on data in cells Deleting rows based on the text in certain cells VBA ThisGuyJohn Excel Programming 5 02-03-2017 03:16 PM
Deleting specific rows in Mail Merge document based on data in cells Excel VBA Macro - Deleting Specific Data based on criteria MD011 Excel Programming 3 12-10-2014 02:15 AM
Deleting specific rows in Mail Merge document based on data in cells Mail Merge to print specific record based on mergefield criterias nicnad Mail Merge 1 02-22-2012 01:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft