PDA

View Full Version : Solved: Delete table cells with bookmark range



stecstec
07-27-2007, 02:03 AM
Hi there, just a quick question:

Is it possible to delete table cells within a specifiied bookmark range?

Ideally I'd have a long table in my document, and have bookmarks set over certain rows in order to delete specific sections as needed.

cheers in advance, Steve.

fionabolt
07-27-2007, 07:50 AM
Does this help you get on your way?

Sub mainroutine()
DeleteCell "cell1"
End Sub
Function DeleteCell(bkmname)
Dim bkm As Bookmark
For Each bkm In ActiveDocument.Bookmarks
If bkm.Name = bkmname Then
If bkm.Range.Information(wdWithInTable) = True Then
bkm.Range.Expand (wdCell)
bkm.Range.Cells.Delete
End If
End If
Next bkm
End Function

fumei
07-27-2007, 12:55 PM
1. Bookmarks can be nested.

2. Bookmarks can be deleted directly.

So say you have five tables.

First, I would (and I always do with any document), bookmark the whole tables themselves. Now each table can be refered to by name. Let's assume you have done that - and BTW, you do not NEED to.

Within Table3 (the whole of which is bookmarked), you have Row 2, Row 4, Row 7 also bookmarked. Named:

Table3R2
Table3R4
Table3R7

You can delete Row 4 directly:ActiveDocument.Bookmarks("Table3R4").Range.DeleteThere......done.

ANY range of a document can be set as a bookmark. A cell, a Row, part of a Row, a column, part of a column, a paragraph, part of paragraph et al.

Anything you can select can be bookmarked.

Any bookmark can be deleted (among other operations) directly, by name.

Cell at Row 5 / Column 4 of the fourth table? Select it, bookmark it as "Table4R5C7". Or any other name that will make sense. Now you can action it directly.
ActiveDocument.Bookmarks("Table4R5C7").Range.Delete

BTW: if you bookmark a cell, then the bookmark IS the cell. Changing content makes no difference.

If cell(2,4) is bookmarked, then if it is blank, then:

Bookmark("name").Range.Text = ""

If you put "Jack and the Bean Stock" into the cell, then:

Bookmark("name").Range.Text = "Jack and the Bean Stock"

The value changes automatically. No need to expand.

But be aware that range on a cell includes the end-of-cell marker. Deleting is not an issue, but if you are extracting content, you need to strip the last two characters.

stecstec
08-02-2007, 04:16 AM
Thank you Fumei & Fionabolt - your comments are much appreciated