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 / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Help with clearing some table cell contents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Lewis - 24 Apr 2007 16:09 GMT
What I need to do is if I have a table of rows x.  Each row
can contain either 1, 2, 4 or 5 cells.  I need to loop through each row in
the table and clear the contents of the Cells 3, 4 and 5 only in the rows
with 5 cells.  all other rows are left alone.

so

Selection.Tables(1).Select
j = Selection.Rows.Count ' i need the number of rows later so stored in
variable now
For rownum = 1 To j
Selection.Tables(1).Rows(rownum).Select

If Selection.Cells.Count = 5 Then

Something here to delete the contents of cells 3, 4 and 5 of the current
row#

Next rownum

any ideas?

Signature

Chris Lewis

Jay Freedman - 25 Apr 2007 02:28 GMT
Hi Chris,

Don't select anything. Use a Range object. When a row has 3 or more
cells, set the Range object to the range of the 3rd cell and then
extend it to cover the rest of the cells to the end of the row. The
.Delete method will then remove any text from those cells (it doesn't
delete the cells themselves).

Sub Demo()
   Dim oRg As Range
   Dim oRow As Row
   Dim j As Long
   
   j = ActiveDocument.Tables(1).Rows.Count
   
   For Each oRow In ActiveDocument.Tables(1).Rows
       If oRow.Cells.Count > 2 Then
           Set oRg = oRow.Cells(3).Range
           oRg.End = oRow.Range.End
           oRg.Delete
       End If
   Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>What I need to do is if I have a table of rows x.  Each row
>can contain either 1, 2, 4 or 5 cells.  I need to loop through each row in
[quoted text clipped - 17 lines]
>
>any ideas?
 
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.