Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2016, 05:58 AM
NorthSuffolk NorthSuffolk is offline Word Macro to delete table row and table header Windows 7 64bit Word Macro to delete table row and table header Office 2016
Novice
Word Macro to delete table row and table header
 
Join Date: Oct 2016
Posts: 5
NorthSuffolk is on a distinguished road
Default Word Macro to delete table row and table header

I have a table where I would like to delete the specific row and/or table if criteria is reached.

The macro needs to prompt for a value and delete all applicable rows (including the table header if the user wishes)




If the user enters '0' in the prompt it needs to delete rows with '0' but ignore '10', '20', '30' etc

Any help would be great.

Thanks,
Reply With Quote
  #2  
Old 10-10-2016, 07:08 AM
gmayor's Avatar
gmayor gmayor is offline Word Macro to delete table row and table header Windows 10 Word Macro to delete table row and table header 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

What exactly might be in the cell to be referenced? Which cell(s) in the row contain the information in question.
__________________
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 10-10-2016, 07:14 AM
NorthSuffolk NorthSuffolk is offline Word Macro to delete table row and table header Windows 7 64bit Word Macro to delete table row and table header Office 2016
Novice
Word Macro to delete table row and table header
 
Join Date: Oct 2016
Posts: 5
NorthSuffolk is on a distinguished road
Default

The content of the table will vary, but will look something along the lines of

Food Type | Sales Total
Apple | 10
Banana | 5
Grape | 1
Reply With Quote
  #4  
Old 10-10-2016, 08:57 PM
gmayor's Avatar
gmayor gmayor is offline Word Macro to delete table row and table header Windows 10 Word Macro to delete table row and table header 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

Based on that information
Code:
Sub RemoveZeroValues()
Dim oTable As Table
Dim oCell As Range
Dim lngCount As Long
    If Not Selection.Information(wdWithInTable) Then
        MsgBox "Put the cursor in the table and run the macro again"
        GoTo lbl_Exit
    End If
    Set oTable = Selection.Tables(1)
    For lngCount = oTable.Rows.Count To 2 Step -1
        Set oCell = oTable.Rows(lngCount).Cells(2).Range
        oCell.End = oCell.End - 1
        If val(oCell.Text) = 0 Then oTable.Rows(lngCount).Delete
    Next lngCount
lbl_Exit:
    Set oTable = Nothing
    Set oCell = Nothing
    Exit Sub
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
  #5  
Old 10-11-2016, 02:15 AM
NorthSuffolk NorthSuffolk is offline Word Macro to delete table row and table header Windows 7 64bit Word Macro to delete table row and table header Office 2016
Novice
Word Macro to delete table row and table header
 
Join Date: Oct 2016
Posts: 5
NorthSuffolk is on a distinguished road
Default

Thanks for the reply - this works in removing zeroes, however it was the ability to delete the table header row by the user which would be really useful.

Thanks.
Reply With Quote
  #6  
Old 10-11-2016, 04:06 AM
gmayor's Avatar
gmayor gmayor is offline Word Macro to delete table row and table header Windows 10 Word Macro to delete table row and table header 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

Add the line
Code:
oTable.Rows(1).Delete
immediately before
Code:
lbl_Exit:
to remove the header row.
__________________
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
  #7  
Old 10-11-2016, 05:04 AM
NorthSuffolk NorthSuffolk is offline Word Macro to delete table row and table header Windows 7 64bit Word Macro to delete table row and table header Office 2016
Novice
Word Macro to delete table row and table header
 
Join Date: Oct 2016
Posts: 5
NorthSuffolk is on a distinguished road
Default

Thanks, that works well.
Reply With Quote
Reply

Tags
table headers, vba macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Macro to delete table row and table header Repeat header of table within another table Dart82 Word Tables 3 04-11-2016 04:15 AM
Word Macro to delete table row and table header How to repeat table header of table within table CTNAM Word Tables 1 04-11-2016 04:14 AM
Delete table lines/Condense table frustrated teacher Word VBA 3 12-14-2015 02:03 AM
Macro Needed to delete Unwanted paragraphs within a table. frustrated teacher Word VBA 0 06-05-2015 12:47 PM
Word Macro to delete table row and table header Unable to delete row below table header clarence Word 2 11-23-2014 02:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:20 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