Deleting cells/rows in a table

G

Guest

I'm sooo close.

I have a table with two cells per row (and I have many rows), I need to
delete the entire row (to include both cells) of selected rows. In doing
this I hope the line feed is also deleted so the row above and the row below
will be back to back with no line space in between.

I have the code written that will clear the selected cells, but have not
figured out how to get rid of the line that is left (hence wanting to delete
the entire row).

I need to use VBA.
I'm using PPT 2003.

Any suggestions?
Thank you
Ron
 
B

Brian Reilly, MVP

brm3
You can modify this to get to the correct row and delete it.
MsgBox ActivePresentation.Slides(1).Shapes(1).Table.Rows.Count

If I were you I'd step through the rows from the bottom up since if
you go from the top to bottom the row after the one you just deleted
will become that index, in this case Row 6 is now row 5

Brian Reilly, MVP
 
G

Guest

Brian,

I'm confused. I don't quite see how this deletes the row. Below is a
snippit of my code (maybe I approached it from the wrong angle). I am going
through each cell (got this code from PPTools) then deleting text. What I
really need to do is delete the row so I get rid of extra lines.

Can you expand on your explanation?

Thank you.

Ron

Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table
With oTbl

For lRow = 1 To .Rows.Count
For lCol = 1 To .Columns.Count
With .Cell(lRow, lCol).Shape

If flag = "TRUE" Then .TextFrame.TextRange.Text = ""

If .HasTextFrame Then
If .TextFrame.HasText Then
Debug.Print .TextFrame.TextRange.Text
Debug.Print "HELLO"
Debug.Print .TextFrame.TextRange.Text


box = .TextFrame.TextRange.Text
If box = "ACTION OFFICER " Then
MsgBox "got it"

.TextFrame.TextRange.Text = ""
flag = "TRUE"
End If
End If
End If
 
B

Brian Reilly, MVP

brm3,
First, I don't think you got this code from PPTools. Steve and I wrote
those tools and I don't think the code is exposed (right Steve?)

I frankly cannot understand what you are doing in your code snippet.
There is no reason to delete the contents of the cell before deleting
the row. Changing the value of a cell would require this which I think
Steve has already helped you with.

Can you please explain more? Steve and I have different styles of
coding and we will not try to confuse you.

Brian Reilly, MVP
 
G

Guest

Brian,

I did get some of the code from Steve (how to find the last table on a
slide), but I thought I got some (reading all the cells) from PPTools
(wanted to make sure credit was where it was due). However, I probably
really messed it up as I was trying to change data in a cell (original plan)
to where I decided I needed to delete the entire row if the second cell was
empty. (Only two cells per row)

1) If the first cell in a row equals some pre-defined string (e.g., Name)
and the next cell is empy (the name was never filled in - who knows why), I
wanted to delete the entire row, not just leave the second cell empty. So I
might get two rows with data in both cells, then I might get one row with the
second cell empty, then the next two rows with data in both cells, etc.
Completely random.

2) I was able to read each cell and check the first cell on each row for
the pre-defined string. At first, I would just null out the first cell if
the second cell was empty. However, the table ended up with extra lines in
it. Since I was at the correct row when I checked the cell content, I was
hoping it would be simple to delete the row (that is why I sent the snippet
to indicate I knew which row needed to be deleted), and I was at that row
when I was inspecting the cell contents.

3) I looked for some hints on how to accomplish, but couldn't really find
anythig describing it. I have deleted rows in excel, but never in power
point.

4) I assumed you had to delete rows to remove that extra line, but maybe
there is another way.

5) I didn't include all of the code so maybe the snippet was misleading.
As you can tell, I don't have a lot of VBA experience.

Thank you for your patience and help.

Ron
 
S

Shyam Pillai

Ron,
I think this is what you are looking for:

Sub Routine()
Dim oTbl As Table
Dim I As Integer
Dim SearchString As String

SearchString = "ACTION OFFICER"

Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table
For I = oTbl.Rows.Count To 1 Step -1
' If the first cell matches the search string and the 2nd cell in the
row is blank
If oTbl.Cell(I, 1).Shape.TextFrame.TextRange.Text = SearchString And _
oTbl.Cell(I, 2).Shape.TextFrame.TextRange.Text = "" Then
oTbl.Rows(I).Delete
End If
Next

End Sub


--
Regards,
Shyam Pillai

Image Importer Wizard
http://skp.mvps.org/iiw.htm
 
G

Guest

Shyam,

This is exactly what I wanted to do. Works perfectly.

Thanks to everyone who helped me with this.

Ron
 
S

Steve Rindsberg

Brian,

I did get some of the code from Steve (how to find the last table on a
slide), but I thought I got some (reading all the cells) from PPTools
(wanted to make sure credit was where it was due).

Probably the PPT FAQ site rather than PPTools per se.
Brian! Leave 'im alone.

Here's a little example code. A table's .Row has a .Delete method that does what you
want, I think. This assumes you've got a table on the current slide and that it's
selected. You'll want to mod it to suit your code:

Sub DeleteRow()
Dim oTable As Table
Set oTable = ActiveWindow.Selection.ShapeRange(1).Table

With oTable
.Rows(2).Delete
End With

End Sub


However, I probably
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top