![]() |
|
#1
|
|||
|
|||
![]() 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, |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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 |
#4
|
||||
|
||||
![]()
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 |
#5
|
|||
|
|||
![]()
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. |
#6
|
||||
|
||||
![]()
Add the line
Code:
oTable.Rows(1).Delete Code:
lbl_Exit:
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
![]()
Thanks, that works well.
|
![]() |
Tags |
table headers, vba macro |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Dart82 | Word Tables | 3 | 04-11-2016 04:15 AM |
![]() |
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 |
![]() |
clarence | Word | 2 | 11-23-2014 02:13 AM |