Re: Iterate cells in a table by Doug
Doug
Wed Apr 09 02:25:46 PDT 2008
Assuming that you want to split the first cell in the new row into two
columns, use
Dim rng As Range
Dim tbl As Table
Dim intCount As Integer
Set rng = ActiveDocument.Range
Set tbl = ActiveDocument.Tables.Add(rng, 2, 1)
With tbl
.Cell(1, 1).Split 1, 3
.Cell(2, 1).Split 1, 2
.Cell(2, 2).Split 5, 2
For intCount = 1 To 5
.Cell(1 + intCount, 2).Range.Text = intCount
Next
.Rows.Add
intCount = .Rows.Count
.Cell(intCount, 1).Split 1, 2
End With
You can't split a cell with
Split 1, 1
as the cell already has one row and one column
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"GraemeR" <GraemeR@discussions.microsoft.com> wrote in message
news:3FD122F1-ED07-42CF-AF7C-ABFB6A62642F@microsoft.com...
> This is the error I was looking to work around:
> 5991: Cannot access individual rows in this collection because the table
> has
> vertically merged cells.
>
> Again, any help will be appreciated,
> Graeme.
>
> This code reproduces the error:
>
> Dim rng As Range
> Dim tbl As Table
> Dim intCount As Integer
>
> Set rng = ActiveDocument.Range
> ActiveDocument.Tables.Add rng, 2, 1
>
> Set tbl = rng.Tables(1)
>
> Set rng = tbl.Rows(1).Range
> rng.Cells(1).Split 1, 3
>
> Set rng = tbl.Rows(2).Range
> rng.Cells(1).Split 1, 2
>
> Set rng = tbl.Rows(2).Cells(2).Range
> rng.Cells.Split 5, 2
>
> For intCount = 1 To 5
> tbl.Cell(1 + intCount, 2).Range.Text = intCount
> Next
>
> tbl.Rows.Add
>
> Dim rw As Row
> Set rw = tbl.Rows(tbl.Rows.Count).Range.Rows(1) ' <== error 5991
> rw.Cells.Split 1, 1, True ' Start of new layout for table