Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-10-2019, 02:53 PM
MathiasFC MathiasFC is offline Macro that deletes all empty rows in selected table Windows 10 Macro that deletes all empty rows in selected table Office 2016
Novice
Macro that deletes all empty rows in selected table
 
Join Date: Jan 2019
Posts: 12
MathiasFC is on a distinguished road
Default


My situation is this: I’ve got a table consisting of 2 columns and an unspecified number of rows. Though all cells in the second column have text, only some of the cells in the first columns have numbers. I need a way of quickly deleting whole rows, when the cell in the first column is empty, but leave the row if the cell in the first column is got a number in it. I imagin it could be as simple as a ‘for loop’ that loops the amount of times there are rows, followed by an ‘if statement’ –

For loop(i)
if cell in column 1 == empty, remove row
i + 1

The problem is I have no idea how to program using the VPA, and would really appreciate the help from someone who does 😊 Thank you in advance for any responses.


What I'm trying to achive:
-Before




Sample Text

Sample Text
1
Sample Text

Sample Text
4
Sample Text

-After

1
Sample Text
4
Sample Text

It's worth noting the text at the bottom of the question doesn't appear in the table I expected it to, so just ignore the 'before' and 'after'.
Reply With Quote
  #2  
Old 02-10-2019, 03:48 PM
Guessed's Avatar
Guessed Guessed is offline Macro that deletes all empty rows in selected table Windows 10 Macro that deletes all empty rows in selected table Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The basic code is as follows.
Code:
Sub wiperows()
  Dim i As Integer
  With Selection.Tables(1)
    For i = .Rows.Count To 1 Step -1
      If Len(.Rows(i).Cells(1).Range.Text) = 2 Then .Rows(i).Delete
    Next i
  End With
End Sub
You may need to complicate it further to deal with errors you might encounter such as:
- the user hasn't put their cursor in the table before running the macro
- there are vertically merged cells which confuses Word when it is looking for a 'row'
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-10-2019, 04:06 PM
MathiasFC MathiasFC is offline Macro that deletes all empty rows in selected table Windows 10 Macro that deletes all empty rows in selected table Office 2016
Novice
Macro that deletes all empty rows in selected table
 
Join Date: Jan 2019
Posts: 12
MathiasFC is on a distinguished road
Default

That's exactly what I was looking for! Thanks so much for taking the time and answering so quickly
Reply With Quote
Reply

Tags
wordvba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro that deletes all empty rows in selected table Delete Empty Table Rows cltay87 Word VBA 4 02-27-2017 04:23 AM
Macro that deletes all empty rows in selected table Macro to delete all empty rows from all tables braddgood Word VBA 15 10-02-2015 01:54 PM
Macro that deletes all empty rows in selected table Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM
Macro that deletes all empty rows in selected table Macro to delete rows with all empty cells ubns Excel Programming 2 08-14-2012 02:01 AM
Temporarily show/hide selected table rows glricht Word Tables 0 12-29-2009 05:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:31 PM.


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