Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2020, 03:12 PM
Blondyvl Blondyvl is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2010
Novice
Remove row in word table if one cell is blank
 
Join Date: Oct 2020
Posts: 7
Blondyvl is on a distinguished road
Default Remove row in word table if one cell is blank

Please would it be possible for someone to help me.

What I'm trying to achieve is, when i click the complete mailmerge button, I'm want any rows in the table that contain a blank cell to delete the whole row and only show the tables for each person if it contains a data for them from the mailmerge.

In the attached document i have added a few extra rows to test to see if i can get any rows to delete, everything in red i want deleting when I complete the mailmerge



The maximum amount of comments and marks each person has is three, I've tried using a table with six rows, and i've also tried making three separate tables, however i can't make any macros do what i'm trying to achieve.

I really would appreciate it if someone could help me.

Many thanks
Attached Files
File Type: docx Remove rows containing blank cells.docx (13.3 KB, 14 views)
Reply With Quote
  #2  
Old 11-03-2020, 09:45 PM
gmayor's Avatar
gmayor gmayor is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro will delete the unwanted rows in the example document:
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 04 Nov 2020
Dim oTable As Table
Dim i As Integer, j As Integer
    For j = ActiveDocument.Tables.Count To 1 Step -1
        Set oTable = ActiveDocument.Tables(j)
        For i = oTable.Rows.Count To 1 Step -1
            oTable.Rows(i).Select
            If Len(oTable.Rows(i).Range) <= 6 Then
                oTable.Rows(i).Delete
            End If
        Next i
        If oTable.Rows.Last.Cells.Count = 4 Then
            oTable.Rows.Last.Delete
        End If
    Next j
    Set oTable = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-05-2020, 12:33 PM
Blondyvl Blondyvl is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2010
Novice
Remove row in word table if one cell is blank
 
Join Date: Oct 2020
Posts: 7
Blondyvl is on a distinguished road
Default

This is fab, you have made my day. thank you so much.
I’ve just tried it, it works when a person has two instruments, however when a person has one instrument, it deletes most of the blank rows but leaves one row underneath. I’m not sure which row I need to amend. Please can you show me which line needs amending. Thank you.
Reply With Quote
  #4  
Old 11-05-2020, 01:20 PM
Blondyvl Blondyvl is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2010
Novice
Remove row in word table if one cell is blank
 
Join Date: Oct 2020
Posts: 7
Blondyvl is on a distinguished road
Default

So sorry I had a zero in one of the rows in the data scources from a formula I was using to transpose the data. It’s working. Thank you so much.
Reply With Quote
  #5  
Old 11-05-2020, 09:52 PM
gmayor's Avatar
gmayor gmayor is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

As this appears to be the result of a mail merge, by using https://www.gmayor.com/MergeAndSplit.htm or
https://www.gmayor.com/individual_merge_letters.htm. with only a minor change you could run the macro from the process on the fly:
Code:
Sub FixTable(oDoc As Document)
'Graham Mayor - https://www.gmayor.com - Last updated - 06 Nov 2020
Dim oTable As Table
Dim i As Integer, j As Integer
    For j = oDoc.Tables.Count To 1 Step -1
        Set oTable = oDoc.Tables(j)
        For i = oTable.Rows.Count To 1 Step -1
            oTable.Rows(i).Select
            If Len(oTable.Rows(i).Range) <= 6 Then
                oTable.Rows(i).Delete
            End If
        Next i
        If oTable.Rows.Last.Cells.Count = 4 Then
            oTable.Rows.Last.Delete
        End If
    Next j
    Set oTable = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #6  
Old 11-06-2020, 12:39 AM
Blondyvl Blondyvl is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2010
Novice
Remove row in word table if one cell is blank
 
Join Date: Oct 2020
Posts: 7
Blondyvl is on a distinguished road
Default

The last thing I’ve been trying to do with this mailmerge is to do a conditional format in cells that contain certain words eg.

Good= Light green
Very good = dark green
Poor = yellow
Bad = orange
Very bad = red

Please would it be possible to show me how to do this.
Many thanks
Reply With Quote
  #7  
Old 11-06-2020, 02:36 PM
macropod's Avatar
macropod macropod is offline Remove row in word table if one cell is blank Windows 10 Remove row in word table if one cell is blank Office 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

See Conditionally Format Mailmerge Output in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum: https://www.msofficeforums.com/mail-...ps-tricks.html
No macros required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove row in word table if one cell is blank How to remove almost a full page of blank space in between Word table rows garrisonsdad Word Tables 4 10-18-2018 09:09 PM
Remove row in word table if one cell is blank Remove blank table rows AFTER mailmerge Formd Mail Merge 5 05-11-2018 03:43 PM
Remove row in word table if one cell is blank 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

Other Forums: Access Forums

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


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