Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General PowerPoint Questions / September 2007

Tip: Looking for answers? Try searching our database.

Deleting cells/rows in a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
brm3 - 11 Sep 2007 17:48 GMT
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
Brian Reilly, MVP - 11 Sep 2007 18:48 GMT
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

>I'm sooo close.
>
[quoted text clipped - 13 lines]
>Thank you
>Ron
brm3 - 11 Sep 2007 20:44 GMT
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

> brm3
> You can modify this to get to the correct row and delete it.
[quoted text clipped - 23 lines]
> >Thank you
> >Ron
Brian Reilly, MVP - 12 Sep 2007 02:15 GMT
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

>Brian,
>
[quoted text clipped - 62 lines]
>> >Thank you
>> >Ron
brm3 - 12 Sep 2007 02:50 GMT
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

> brm3,
> First, I don't think you got this code from PPTools. Steve and I wrote
[quoted text clipped - 76 lines]
> >> >Thank you
> >> >Ron
brm3 - 12 Sep 2007 03:06 GMT
Brian

Here is the link I used to grab some of the code.
http://www.pptfaq.com/FAQ00790.htm

Ron

> Brian,
>
[quoted text clipped - 114 lines]
> > >> >Thank you
> > >> >Ron
Shyam Pillai - 12 Sep 2007 13:26 GMT
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

Signature

Regards,
Shyam Pillai

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

> Brian,
>
[quoted text clipped - 128 lines]
>> >> >Thank you
>> >> >Ron
brm3 - 12 Sep 2007 20:08 GMT
Shyam,

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

Thanks to everyone who helped me with this.

Ron

> Ron,
> I think this is what you are looking for:
[quoted text clipped - 150 lines]
> >> >> >Thank you
> >> >> >Ron
Steve Rindsberg - 12 Sep 2007 21:42 GMT
> 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
> 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  
[quoted text clipped - 109 lines]
> > >> >Thank you
> > >> >Ron

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.