![]() |
#1
|
|||
|
|||
![]()
I have a long (15 pages or so) table 6 or 7 columns wide that I simply need to reverse the order of the lines in the table. This seems like a simple task for which someone might have already written a macro (or could easily write) The process, I'm sure, would involve adding a column to the left hand side and using it to number the rows and then sorting on this column and deleting it. I don't necessarily want a column that simply numbers the lines when all is said and done.
Searching for this didn't seem to yield anything I could use. Let me know if I'm wrong. Thanks. R Joslin |
#2
|
|||
|
|||
![]()
You don't need a macro to do this.
1. Add your temporary column 2. Define the order you want the rows indexed 3. Sort the table on the temporary column 4. Remove the temporary table |
#3
|
|||
|
|||
![]() Quote:
It's true, Greg, that I might not NEED a macro for this, but isn't the whole purpose of macro to automate tasks? I'm NOT trying to sound whiny or snarky. I tried the above process and no doubt did something wrong and it didn't produce the results I wanted, so I'm taking the lazy way out and wanting someone else to give me a macro that will accomplish it. ![]() Thanks, however, for confirming that I had the right idea. I'm sure there must be a way I can do those 4 steps from the keyboard--I'm still trying to get over the fact that one can't include mouse clicks in macros. I was sure I had done so in the distant past when recording a macro, but I was told authoritatively that this probably was not so. Thanks, anyway. I'll try the hammer and tongs method again and see what happens. Good day. ![]() RJ |
#4
|
|||
|
|||
![]() Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oTbl As Table Dim lngIndex As Long Set oTbl = Selection.Tables(1) oTbl.Columns.Add For lngIndex = 1 To oTbl.Rows.count oTbl.Cell(lngIndex, oTbl.Columns.count).Range.Text = lngIndex Next lngIndex oTbl.Sort False, oTbl.Columns.count, , wdSortOrderDescending oTbl.Columns(oTbl.Columns.count).Delete End Sub |
#5
|
|||
|
|||
![]() Quote:
I'm astounded that so small a macro could accomplish the task. I'll certainly try it. Am I right to assume I start with the table "selected"? But... ![]() Before I saw this reply I was planning to ask you the question below; I'm still trying to learn how to do it manually as you suggested. As it turns out I already have a blank column (the first one) on the left of the table I’m try to reverse. Can I just put the numbers in that column and then sort on it, and later just “clear contents” of that column to get it back to blank again? Or even delete the column once I’m done sorting and then add a new blank column? I was able to select the column and get numbers in each cell, but was stuck on how to sort the table based on the numbers in column 1. Sorry to seem (or BE) so dense. RJ |
#6
|
|||
|
|||
![]()
Yes
Yes Select the table. Table Layout>Sort Sort by Column 1 Ascending |
#7
|
||||
|
||||
![]()
Here's an even more efficient version of Greg's macro - with error checking:
Code:
Sub TblSort() Application.ScreenUpdating = False Dim r As Long, c As Long With Selection If .Information(wdWithInTable) = False Then Exit Sub With .Tables(1) .Columns.Add c = .Columns.Count For r = 1 To .Rows.Count .Cell(r, c).Range.Text = r Next .Sort False, c, , wdSortOrderDescending .Columns(c).Delete End With End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
Thanks to Paul E.
I'll try your macro as well Can you recommend a "book" (or similar digital item) that would be a good introduction to VBA for someone who (like me) has extensive history of BASIC programming? I think I'd enjoy doing some programming again. |
#9
|
||||
|
||||
![]()
I don't have any VBA book recommendations - I've never read any books on VBA.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
![]()
I constructed a small table to test your macro and it worked perfectly. Thanks.
I found that I could do it manually as well using your brief instructions, thanks again. |
![]() |
Tags |
order of tables, reversing order |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
hammad | Word | 10 | 06-20-2019 09:01 AM |
reverse order of paragraphs, word 2010 | moorea21 | Word VBA | 1 | 08-02-2018 03:47 AM |
![]() |
equity | PowerPoint | 3 | 04-04-2014 12:33 AM |
![]() |
bknollman3 | PowerPoint | 2 | 03-23-2013 06:34 AM |
Reverse order of headings throughout Word | my_vine_figtree | Word VBA | 1 | 08-17-2010 01:46 AM |