Go to last row in table

A

Arno

Hi,

I want to jump to the first cell of the last row in a table, when the cursor
is already within that table. There are multiple tables in the document.

I tried this:

Public Sub Last_row()
If Selection.Information(wdWithInTable) Then
X = Selection.Information(wdMaximumNumberOfRows)
Selection.Rows(X).Cells(1).Select
End If
End Sub

but it fails at the Select line.
Can anyone help?

Regards,

Arno
 
R

Russ

Arno,
Since you didn't have X rows selected, it couldn't continue.

But there is at least 1 table that is involved with the selection and
happens to be the first table in that selection, so it understands this:
Selection.Tables(1).Rows(X).Cells(1).Select
 
A

Arno

Thanks a lot Russ!
I assumed that Tables(1) meant the first table in the document. I suppose
now it means the first table in the selection. Right?


Regards,

Arno
 
R

Russ

Correct.
Selection.Tables(1) = first table in selection.
Activedocument.Content.Tables(1) = first table in document

If myRange is set to a Footer then myRange.Words(1) = first word in that
footer.
Etc.
 

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