Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
roberto-cruz roberto-cruz is offline
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   Report Post  
Posted to microsoft.public.word.tables
Suzanne S. Barnhill Suzanne S. Barnhill is offline
external usenet poster
 
Posts: 33,624
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   Report Post  
Posted to microsoft.public.word.tables
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
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.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count number of rows~ drybones New Users 5 March 7th 13 09:17 AM
Count number of rows in table PamKT Microsoft Word Help 6 August 30th 06 09:32 AM
Count table rows with specific value in a column kaz Tables 4 May 28th 06 04:39 AM
Mail Merge could create new rows in a existing table danielgatley Mailmerge 1 April 18th 05 02:29 PM
hi, how can i add rows in existing table in word using macro, wit. Jeeg Tables 1 February 16th 05 10:44 AM


All times are GMT +1. The time now is 09:35 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"