#1
|
|||
|
|||
Delete table if cell has data
I've used this code to delete a table if a cell was empty, but now I need to do the opposite, that is delete the table if a cell contains data. Code:
Public Sub SHUNT() Dim oRng1 As Range With ActiveDocument Set oRng1 = .Range(Start:=.Bookmarks("BK_SHUNTS").Range.End, End:=.Bookmarks("BK_SHUNTE").Range.Start) If Len(oRng1.Tables(1).Cell(1, 1).Range) = 2 Then oRng1.Tables(1).Delete GoTo finish Else Dim t1 As Table Set t1 = ActiveDocument.Bookmarks("BK_SHUNT").Range.Tables(1) End If End With finish: End Sub Last edited by macropod; 05-06-2013 at 08:56 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
Doing the opposite is as simple as changing '= 2' to '> 2'
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab. Please also preview your posts when doing so - the code you posted had no structure at all, all being output as an ordinary string.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word VBA: Cannot Edit Range (Delete characters except the first in a table cell) | tinfanide | Word VBA | 3 | 04-27-2012 09:48 AM |
How can I delete the content of a cell in column if the cell value is more than 1000? | Learner7 | Excel | 2 | 06-27-2011 05:44 AM |
Move data from 1 cell to another cell | Catalin.B | Excel | 1 | 06-25-2011 12:51 PM |
How to delete first 6 Digits and one Space from a CELL? | Learner7 | Excel | 3 | 08-10-2010 04:06 AM |
Auto-populate an MS Word table cell with text from a diff cell? | dreamrthts | Word Tables | 0 | 03-20-2009 01:49 PM |