A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

how can I count the number of rows in an existing table



 
 
Thread Tools Display Modes
  #1  
Old September 29th, 2007, 05:10 PM posted to microsoft.public.word.tables
roberto-cruz[_2_]
external usenet poster
 
Posts: 1
Default how can I count the number of rows in an existing table

i've got a table, about 45 rows, but I want a way to count the exact number
of rows without adding a separate column on the left and numbering it from 1
to 45 or whatever. because i don't want that column to appear in the table
when I print it or display it, I just want a line a the bottom of the doc
that says: " there are "n" rows in your table.
  #2  
Old September 29th, 2007, 06:21 PM posted to microsoft.public.word.tables
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default how can I count the number of rows in an existing table

There are various ways to tell *you* the number of rows in a table, though I
don't know of any that allow you to put this information in the table itself
except manually. But see
http://word.mvps.org/FAQs/AppErrors/...eIncorrect.htm (the
TableCellHelper macro available from that page) and
http://gregmaxey.mvps.org/Table_Cell_Data.htm. It's possible that if you
write Greg he can add a function to the macro to allow you to place the
results in your table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"roberto-cruz" wrote in message
news
i've got a table, about 45 rows, but I want a way to count the exact

number
of rows without adding a separate column on the left and numbering it from

1
to 45 or whatever. because i don't want that column to appear in the table
when I print it or display it, I just want a line a the bottom of the doc
that says: " there are "n" rows in your table.


  #3  
Old September 30th, 2007, 10:41 AM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default how can I count the number of rows in an existing table

You could use the following solution:

Preconditions: Your table must have at least 2 columns (otherwise, the
explanation below will need adjustments).

1. At the end of your table, add a row to be used for the count info.
2. In the first cell in the info row, insert a MacroButton field as follows:

3. Press Ctrl+F9 to insert a set of field braces.
4. Between the braces, type:

MacroButton CountTableRows Double-click here to count rows

5. Press F9 to update the field (if this does not toggle field codes, press
Alt+F9).
6. To make it easy to distinguish the field from the rest of the content,
you may e.g. add yellow highlight to it.

Note that "Double-click here to count rows" is the text that will appear in
the field. You can change the text as you wish.

Now you need a macro named "CountTableRows". The macro will run whenever a
user double-clicks the MacroButton field. Such macro is found below (comments
are included in the macro to tell what happens) - it inserts the text "There
are [n] rows in your table (incl. this row)" in the last table cell (it
replaces the current cell content and you don't need to type any of the text
manually).

Sub CountTableRows()
Dim n As Long
Dim oRange As Range

'Since last operation was a click on the MacroButton field,
'the selection is in the table
With Selection
'Go to the last cell
'Done as follows to prevent errors in case of merged cells
.Start = .Tables(1).Range.Characters.Last.Start - 1
'Collapse selection
.End = .Start
'The last cell must be used as range later
Set oRange = .Cells(1).Range
'Find max number of rows in table
n = Selection.Information(wdMaximumNumberOfRows)
'Replace content of last cell by updated info
oRange.Text = "There are " & n & " rows in your table (incl. this
row)"
End With
'Clean up
Set oRange = Nothing
End Sub

The macro must be stored in a place that makes it available to all users.
This can be:
- in the document itself (i.e. the document with the table)
- in the attached template, provided the template is available to all users
(not your Normal.dot)
- in a global template, i.e. a template stored in Word's Startup folder

For more information about MacroButton fields, see:
http://www.word.mvps.org/FAQs/TblsFl...acroButton.htm

For information about how to install a macro, see:
http://www.gmayor.com/installing_macro.htm

NOTE: if the users need to add rows to the end of the table, it may be
better to place the info row at the top of the table or somewhere else. In
that case, adjustments to the macro are needed. You only need to be able to
uniquely identify the table in which to count rows and the place to put the
updated count.

The user must double-click the MacroButton field to update the rows count.
It is not updated automatically.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Suzanne S. Barnhill" wrote:

There are various ways to tell *you* the number of rows in a table, though I
don't know of any that allow you to put this information in the table itself
except manually. But see
http://word.mvps.org/FAQs/AppErrors/...eIncorrect.htm (the
TableCellHelper macro available from that page) and
http://gregmaxey.mvps.org/Table_Cell_Data.htm. It's possible that if you
write Greg he can add a function to the macro to allow you to place the
results in your table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"roberto-cruz" wrote in message
news
i've got a table, about 45 rows, but I want a way to count the exact

number
of rows without adding a separate column on the left and numbering it from

1
to 45 or whatever. because i don't want that column to appear in the table
when I print it or display it, I just want a line a the bottom of the doc
that says: " there are "n" rows in your table.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.