How to refer to the last cell in a table without ColumnIndex?

B

Benjamino5

I need to determine if a cell is last in a table, but I can't check the
ColumnIndex because the tables don't have consistent cell widths, so it gives
me an error. Here's the old code that uses ColumnIndex:

CellIsLast = IIf((theCell.Range.Information(wdStartOfRangeColumnNumber) =
theTable.Columns.Last.Index _
And theCell.Range.Information(wdStartOfRangeRowNumber) =
theTable.Rows.Last.Index), True, False)

What I need to do now is determine if "theCell" is in the last row of the
table AND that it is the last cell in that row.

How can I tell where a cell is in a row? I feel like this should be very
simple, but I'm just not seeing it, so code samples would be very greatly
appreciated.

Thanks!
Ben
 
T

Tony Jollans

Firstly your code is not using ColumnIndex - try this instead

cellislast = (thecell.rowindex = thetable.rows.count) _
and (thecell.columnindex = thetable.columns.count)

However, for a complete solution, you must define what you mean by the last
cell in your table as there is not necessarily a cell in the 'last' row and
'last' column.
 
H

Helmut Weber

Hi Benjamin,

maybe something like that.

If the second next character after the cell
is not in a table, then the cell is the last one:

Dim rTmp As Range
Set rTmp = selection.Cells(1).Range
MsgBox rTmp.Characters.Last.Next.Next.Information(wdWithInTable)

You might have to collapse the selection to its end beforehand.
or set rTmp to
selection.Cells(selection.Cells.Count).Range
if the selection encompasses more than one cell...

HTH, anyway.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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