Table reference and calculation

P

pf

I have a document that has several tables, (about 35+). These documents will
be used to create some base documents for other staff to use. The tables
represent different "sections" of the document where staff will enter scores
for questions in the tables. The first section of the document may have
between 3-20 tables and the scores will need to be calculated. But I will
not know exactly how many tables there will be in the first section from
document to document.

How can I check to determine how many tables are in the first section and
then calculate the data in the second column? I do not want to include
tables in the total that are in the rest of the document.

Is there a way to name a table?
I can bookmark a table, but not sure how to reference the cell value.

Any help is appreciated.

thanks
pf
 
D

Doug Robbins - Word MVP

I've had to do a bit of guessing about exactly what you have, but the
following code should sum all of the values entered into the second row of
the second column of all of the tables in the first Section of the document,
where Section is what is meant by that word in Word

Dim i As Long, j As Long
Dim rngeresult As Range
Dim tally As Long
tally = 0
With ActiveDocument.Sections(1).Range
For i = 1 To .Tables.Count
With .Tables(i)
For j = 2 To .Rows.Count
Set rngeresult = .Cell(j, 2).Range
rngeresult.End = rngeresult.End - 1
tally = tally + Val(rngeresult.Text)
Next j
End With
Next i
End With
MsgBox tally


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

pf

Doug thanks for the reply, your code helped me fix the issue I was having.

now is there a way to disable all the fields in a table column that do not
have bookmark names? I can loop through the fields but not sure how to
reference them if they do not have a bookmark name..
 
D

Doug Robbins - Word MVP

It's starting to sound to me like you should be using formfields as used in
a document that is protected for Filling in Forms.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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