Reputation: 11
I'm trying to figure out a way to select the last cell in a table in word. I have a document that auto-generates with one table, in which all blank cells are merged into an empty column in the bottom-right. Is there code that can select the bottom-right cell in a table?
Upvotes: 1
Views: 5724
Reputation: 7850
As your table contains merged cells you may find that referring to the column count gives you an error.
Use this instead:
Private Sub SelectLastCell()
With ActiveDocument.Tables(1).Rows.Last
.Cells(.Cells.Count).Range.Select
End With
End Sub
Edit:
To select the last cell of the last column simply reverse the logic, like so:
Private Sub SelectLastCell()
With ActiveDocument.Tables(1).Columns.Last
.Cells(.Cells.Count).Range.Select
End With
End Sub
Upvotes: 2