GET ROW COUNT OF A TABLE

D

dipali

I have a table with cells merged together.some cells are having row spans as
well as col spans

now i want to navigate through the table and find out value in each cell of
the table.I am doing this by two for loops first one increments row number
and second one increments column number.This code is working fine if any of
the cells have not merged with other cell.

If i merge some of the cells then this code gives error saying can not
access individual rows since there are vertically merged cells.


Do you have solution for this problem?
 
J

Jonathan West

dipali said:
I have a table with cells merged together.some cells are having row spans
as
well as col spans

now i want to navigate through the table and find out value in each cell
of
the table.I am doing this by two for loops first one increments row number
and second one increments column number.This code is working fine if any
of
the cells have not merged with other cell.

If i merge some of the cells then this code gives error saying can not
access individual rows since there are vertically merged cells.


Do you have solution for this problem?

This code example will show you how to cope

Sub SetCellNumbers()
Dim oCell As Cell
For Each oCell In ActiveDocument.Tables(1).Range.Cells
oCell.Range.InsertAfter oCell.RowIndex & " " & oCell.ColumnIndex
Next oCell
End Sub
 
H

Helmut Weber

Hi,
you can still loop through all cells like this,
Dim oCll As Cell
With ActiveDocument.Tables(1).Range
For Each oCll In .Cells
oCll.Select
Next
End With
or use for i = 1 to ActiveDocument.Tables(1).Range.Cells.Count
You also can access r (row) and c (col) of the given cell:
r = oCll.RowIndex
c = oCll.ColumnIndex
If you have merged cells (1,2) and (2,2) vertically,
then cell(2,2) has vanished. Though, with horizontally merged cells,
this method doesn't work, and I wonder, if there is a solution at all.
 

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