Auto number a column in table using SEQ

K

kaz

Hi there

I have created a table and have used the SEQ formula to have a
sequential number in the first column. When I copy the row the SEQ
works fine - i.e. it auto-increments the number. But if I tab through
the row (the last row of the table) and it creates a new row the SEQ is
obviously not there. I can understand the logic of that but is there
some other way of having a sequential number automatically
incrementating that will work if I copy the row as well as tabbing
through the last row on the table.

Cheers
Kaz
 
K

kaz

Actuslly, can I add another bit to this question? I see that I can use
standard list numbering to achieve the sequential number bit. But I am
also using a Count function to count the number of rows. When I use
standard list numbering my Count function doesn't work anymore.
 
D

Doug Robbins - Word MVP

Where and for what are you using the count function. The number in the last
row will equal the count will it not?

--
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
 
K

kaz

I have a field, outside of the table, that needs to display the count
of the number of items in the table (excluding the header row).
 
S

Suzanne S. Barnhill

You might want to have a look at
http://gregmaxey.mvps.org/Table_Cell_Data.htm. If this macro doesn't do what
you need, perhaps Greg could enhance it so that it would. I would think that
any macro that could put information in the status bar could also write it
to a document property or variable that could be picked up in the doc with a
DocProperty or DocVariable field.
 
K

kaz

Wow, that looks pretty complex. I thought I could do something as
simple as using Count pointing to the column in the table (where I have
bookmarked the table). I do have a good book that shows me how to get
the information from the status bar so will work on that. If there is a
simpler solution can someone please let me know.
 
G

Greg Maxey

Alot will depend on how you define an "item." Do you mean a cell containing
any text?

Something like this may do. You can nest a docvarialbe field in a macro
button field to execute:

Sub ScratchMacro()
Dim oTbl As Word.Table
Dim i&
Dim rowCnt&
Dim colCnt&
Dim myVar As Variable
Set oTbl = ActiveDocument.Tables(1)
For rowCnt = 2 To oTbl.Rows.Count
For colCnt = 1 To oTbl.Columns.Count
If Len(oTbl.Cell(rowCnt, colCnt).Range.Text) > 2 Then
i = i + 1
End If
Next colCnt
Next rowCnt
ActiveDocument.Variables("myVar").Value = i
ActiveDocument.Fields.Update
End Sub

The field will look something like this:

{ Macrobutton Scratchmacro {DocVariable myVar}}
 
K

kaz

Yes, I guess a cell containing any text. What I have is a table where
the first column is a sequential number, automatically generated for
each new row. I am currently creating that number just using standard
list numbering. I did have my field (outside of the table) simply doing
a COUNT on that first column but that doesn't work. I am guessing that
is because Word doesn't recognise the content of the field as being
numeric?!? So if I use the code described by Greg, how do I ensure that
is pointed to that specific table (as my document has a few other
tables in it). When I was trying to do this using COUNT I had
bookmarked the table in question and used that bookmark name in the
COUNT function. Do I just change the "Set oTbl" statement to point to
the bookmark?
 
G

Greg Maxey

Kaz,

Provided that your bookmark spans only the table of interest, you could use
this line (all on one line):

Set oTbl = ActiveDocument.Bookmarks("mytable").Range.Tables(1)

where "mytable" stands in for the name of your bookmark.
 
K

kaz

Hi Greg

I'm getting there (slowly). So, my macro is now giving me the result I
want and I can get the result displayed in the required place in the
document. But I have achieved this by manually running the macro then
updating the field using F9. I am guessing that the command "{
Macrobutton Scratchmacro {DocVariable myVar}} " that you supplied is
supposed to run the macro as well as displaying the variable but I
can't get that to work. I'm (obviously) new to all of this so it is
probably the way I am creating / recording the macro or the actual
syntax. Can you please just help me one more time?

Cheers
Kaz
 
G

Greg Maxey

Kaz

{macrobutton scratchmacro {docvariable myvar}}

Is a DocVariable field, nested in a macrobutton field.

The { } pairs are entered with CTRL+F9. When the field results are
displayed are you will see is the count or the number. If you doubleclick
that number, you will fire the macro to recalculate. See:
http://gregmaxey.mvps.org/Word_Fields.htm for more on Word fields.
 
K

kaz

Okey dokey. Got that bit working. But, is there some other way of
executing the macro? I will be providing the document to users to fill
in. I am not sure about getting them to double-click to run the macro.
Other templates we have created require the user to Select All and then
Press F9. Is there an alternative method for running the macro?
 
G

Greg Maxey

Kaz,

You could add a prompt:
{ Macrobutton Scratchmacro "Double click to count items: { Docvariable
myVar }" }

AFAIK other than that, you would have to assign the macro to a keyboard
shortcut, menu, or toolbar icon.
 

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