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?