Fill a Word table column with successive integers.
Posted on 2015-01-16
I have more than one table in a word document. One of those tables spreads over several pages, and my cursor is in that table in a specific column named “Ix” (for index). I would like a quick and dirty function that will fill that column with consecutive integers, starting in row 2 and running from 1 to the end of the column. That will preserve the current order of the data. If some subsequent editing or sorting mixes up the rows, I can always return the data to its original order by sorting on that “Ix” column.
I could solve the problem if I knew the table number and column number of the cursor location.
If the column I want filled is number six in the second table of the document, I could then use something like this:
Set Tbl = ActiveDocument.Tables(2)
Set Col = Tbl.Columns(6)
MaxRows = Tbl.Rows.Count
For i = 1 To MaxRows - 1
Col.Cells(i + 1).Range.Text = i
Any suggestions either as to determining the Table number and Column number, or to use something else entirely are most welcome.
JRA in Priddis, Alberta