Loop to count cells

S

skrimpy

Ill try this question a different way. Using Word 2000, I have a tabl
that stretches from one page to the next. I want to write a loop tha
will count the number of rows in each page so that I can jump to th
last row in any page but not the end of the table(The number of row
will be variable).

Ive written this loop to count the number of cells in the existin
table on page one(excluding the cells on page two in the count), an
return the number below the current table. Instead of output being th
the number of rows on page one, it prints the number "1". Thanks fo
any help that any can give me!

Sub CountCells()
Dim X, Y As Integer
X = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
Y = 1 ' Initialize variables
Do While X < 2 'Loop
Selection.MoveDown Unit:=wdLine, Count:=1 ' Move down a row.
Y = Y + 1 'Increment Y
Loop
Selection.EndKey Unit:=wdColumn
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:=Y
End Su
 
D

Doug Robbins - Word MVP

The following code will select the last cell on the page

Dim myrange As range
Set myrange = Selection.Bookmarks("\Page").range
myrange.End = myrange.End - 2
myrange.Collapse wdCollapseEnd
myrange.Cells(1).range.Select


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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