Reverse table order/number rows

J

jessim

How can I:

a) Reverse the order of a table

and

b) Automatically number each row?

Thanks,
Jess
 
D

Doug Robbins - Word MVP

Use a macro containing the following code

Dim i As Long
With Selection.Tables(1)
.Columns.Add beforecolumn:=.Columns(1)
For i = 2 To .Rows.Count
.Cell(i, 1).Range.Text = i - 1
Next i
.SortDescending
End With


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

jessim

Hi Doug,

The macro works great! Just one little problem: after it ran, the
rows are now numbered descendingly 84-1 instead of 1-84 (84 rows in my
table, natch). Is there a way to just reverse that 1 numbering column
alone?

Thanks again,
Jess
 
D

Doug Robbins - Word MVP

Use

Dim i As Long
With Selection.Tables(1)
.Columns.Add beforecolumn:=.Columns(1)
For i = 2 To .Rows.Count
.Cell(i, 1).Range.Text = .Rows.Count - i + 1
Next i
.SortAscending
End With

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

jessim

I think it's more due to my unfamiliarity with how macros work that I
just ended up accidentally deleting/fudging around with them. After
they ran, my tables ended up looking funny, so I did a workaround by
copy-and-pasting the first column to another document and reversing it
there, then pasting it back. Otherwise, the macros worked great and
did their job :)

Thanks a lot,
Jess
 

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