Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
I have a table with two columns. The first column has names of items, each
item in its own row. I indent the items (using styles) if they are related to the item directly above it. I want to sort this table, keeping the indented item below the related item. I can't figure out how to do this. The indented items just get sorted normally and end up separated from the related name. An example of my table before sorting: Lamp Book Moby Dick Desk When I sort, it looks like this: Book Desk Lamp Moby Dick I want it to end up looking like this: Book Moby Dick Desk Lamp Any idea how I can accomplish this (other than manually sorting)? |
#2
![]() |
|||
|
|||
![]()
Hi Dan,
To keep the related items together, they must be in the *same* row. In your example, Book and Moby Dick have to be in the same cell. You can prepare this by selecting a group of related items in the first column and clicking Table Merge Cells. Then select the matching group of cells in the second column and merge them (you can just press F4 to repeat the action). Do this for each group of related items. After you sort, if you feel you need to return to separate rows, you can do it with the Table Split Cell command. Unfortunately it won't be as easy as the merge, since Word's default is to split the entry into more columns in the same row, rather than more rows in the same column. You'll have to change the settings in the Split dialog each time. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Sat, 1 Jan 2005 00:39:03 -0800, "Dan Corban" wrote: I have a table with two columns. The first column has names of items, each item in its own row. I indent the items (using styles) if they are related to the item directly above it. I want to sort this table, keeping the indented item below the related item. I can't figure out how to do this. The indented items just get sorted normally and end up separated from the related name. An example of my table before sorting: Lamp Book Moby Dick Desk When I sort, it looks like this: Book Desk Lamp Moby Dick I want it to end up looking like this: Book Moby Dick Desk Lamp Any idea how I can accomplish this (other than manually sorting)? |
#3
![]() |
|||
|
|||
![]()
Thanks for the reply. Your method seems close to what I want, but there are a
few problems. When I only select the first column, I do not have the option to merge cells. That command is greyed out. I must select the entire rows before merge is an option. Also, I sometimes have several levels of indentation. For example: Book 1976 War and Peace Moby Dick 1977 Star Wars Ideally, the sublevels would be sorted as well. I am beginning to think that I am asking too much for the built-in Word functions. Maybe there is a way to do this programmatically? "Jay Freedman" wrote: To keep the related items together, they must be in the *same* row. In your example, Book and Moby Dick have to be in the same cell. You can prepare this by selecting a group of related items in the first column and clicking Table Merge Cells. Then select the matching group of cells in the second column and merge them (you can just press F4 to repeat the action). Do this for each group of related items. After you sort, if you feel you need to return to separate rows, you can do it with the Table Split Cell command. Unfortunately it won't be as easy as the merge, since Word's default is to split the entry into more columns in the same row, rather than more rows in the same column. You'll have to change the settings in the Split dialog each time. |
#4
![]() |
|||
|
|||
![]()
Hi Dan,
I don't understand the problem with selecting only cells in the first column (specific cells, not the entire column) -- it works when I do it. That isn't going to matter to you anyway, because the second part of your proposed method can't be done in Word except manually, line by line, unless you care to do a lot of preparation. I've done something of this sort to prepare a multilevel index for a book, but I planned ahead and made the entries with everything in place from the beginning. Because the finished index was some 8000 entries -- and because I was being paid to do the job -- it was worth the effort. First, each row must contain all the information from the preceding levels. For your new example, I would have created these rows, perhaps in this order: Book, 1977, Star Wars Book, 1977 Book, 1976, War and Peace Book, 1976 Book, 1976, Moby Dick Book After all entries are created this way, I run a single sort over the entire list. That puts the sample in this order: Book Book, 1976 Book, 1976, Moby Dick Book, 1976, War and Peace Book, 1977 Book, 1977, Star Wars As part of the template for this index, I created several styles: a base paragraph style, a one-indent paragraph style, a two-indent paragraph style, and a hidden-font character style. I also wrote a macro that examines each pair of rows, working from the end of the document toward the beginning. If the two rows have the same first two parts (using the comma as the separator between parts), the two-indent style is applied to the second row, and the shared parts are marked with the hidden style. If they have only the first part in common, the one-indent style and the hidden style are applied. If they have nothing in common, only the base style is used. The macro is considerably more complex than the explanation implies because it handles a number of special cases, so it wouldn't be suitable for your problem as is. The general idea still applies, though. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Sat, 1 Jan 2005 08:55:02 -0800, "Dan Corban" wrote: Thanks for the reply. Your method seems close to what I want, but there are a few problems. When I only select the first column, I do not have the option to merge cells. That command is greyed out. I must select the entire rows before merge is an option. Also, I sometimes have several levels of indentation. For example: Book 1976 War and Peace Moby Dick 1977 Star Wars Ideally, the sublevels would be sorted as well. I am beginning to think that I am asking too much for the built-in Word functions. Maybe there is a way to do this programmatically? "Jay Freedman" wrote: To keep the related items together, they must be in the *same* row. In your example, Book and Moby Dick have to be in the same cell. You can prepare this by selecting a group of related items in the first column and clicking Table Merge Cells. Then select the matching group of cells in the second column and merge them (you can just press F4 to repeat the action). Do this for each group of related items. After you sort, if you feel you need to return to separate rows, you can do it with the Table Split Cell command. Unfortunately it won't be as easy as the merge, since Word's default is to split the entry into more columns in the same row, rather than more rows in the same column. You'll have to change the settings in the Split dialog each time. |
#5
![]() |
|||
|
|||
![]()
Another approach I've used that worked pretty well:
Format the rows that should sort along with the previous row as "hidden", and set the view to not show hidden text. If you sort now, the hidden rows will just move along with the preceeding visible rows. In your case, it shouldn't be too hard to write a macro that loops all rows, checks for indents, and hides the row if it finds an indent. Greetings, Klaus "Jay Freedman" wrote: Hi Dan, I don't understand the problem with selecting only cells in the first column (specific cells, not the entire column) -- it works when I do it. That isn't going to matter to you anyway, because the second part of your proposed method can't be done in Word except manually, line by line, unless you care to do a lot of preparation. I've done something of this sort to prepare a multilevel index for a book, but I planned ahead and made the entries with everything in place from the beginning. Because the finished index was some 8000 entries -- and because I was being paid to do the job -- it was worth the effort. First, each row must contain all the information from the preceding levels. For your new example, I would have created these rows, perhaps in this order: Book, 1977, Star Wars Book, 1977 Book, 1976, War and Peace Book, 1976 Book, 1976, Moby Dick Book After all entries are created this way, I run a single sort over the entire list. That puts the sample in this order: Book Book, 1976 Book, 1976, Moby Dick Book, 1976, War and Peace Book, 1977 Book, 1977, Star Wars As part of the template for this index, I created several styles: a base paragraph style, a one-indent paragraph style, a two-indent paragraph style, and a hidden-font character style. I also wrote a macro that examines each pair of rows, working from the end of the document toward the beginning. If the two rows have the same first two parts (using the comma as the separator between parts), the two-indent style is applied to the second row, and the shared parts are marked with the hidden style. If they have only the first part in common, the one-indent style and the hidden style are applied. If they have nothing in common, only the base style is used. The macro is considerably more complex than the explanation implies because it handles a number of special cases, so it wouldn't be suitable for your problem as is. The general idea still applies, though. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Sat, 1 Jan 2005 08:55:02 -0800, "Dan Corban" wrote: Thanks for the reply. Your method seems close to what I want, but there are a few problems. When I only select the first column, I do not have the option to merge cells. That command is greyed out. I must select the entire rows before merge is an option. Also, I sometimes have several levels of indentation. For example: Book 1976 War and Peace Moby Dick 1977 Star Wars Ideally, the sublevels would be sorted as well. I am beginning to think that I am asking too much for the built-in Word functions. Maybe there is a way to do this programmatically? "Jay Freedman" wrote: To keep the related items together, they must be in the *same* row. In your example, Book and Moby Dick have to be in the same cell. You can prepare this by selecting a group of related items in the first column and clicking Table Merge Cells. Then select the matching group of cells in the second column and merge them (you can just press F4 to repeat the action). Do this for each group of related items. After you sort, if you feel you need to return to separate rows, you can do it with the Table Split Cell command. Unfortunately it won't be as easy as the merge, since Word's default is to split the entry into more columns in the same row, rather than more rows in the same column. You'll have to change the settings in the Split dialog each time. |
#6
![]() |
|||
|
|||
![]()
I tried your method and it does not work for me. All hidden rows simply get
sorted to the top of the table. Maybe I am missing a key step to your method, but this is what I did: Show/Hide is off. Select the entire row. Go to Font properties and select "hidden". Select Table - Sort and sort as I normally do. Turn Show/Hide on. I tried several variations of your method and the end result is always the hidden rows sort to the top. I am using Word 2002. Maybe the hidden sort behavior is different in another version? "Klaus Linke" wrote: Format the rows that should sort along with the previous row as "hidden", and set the view to not show hidden text. If you sort now, the hidden rows will just move along with the preceeding visible rows. In your case, it shouldn't be too hard to write a macro that loops all rows, checks for indents, and hides the row if it finds an indent. |
#7
![]() |
|||
|
|||
![]()
On Sat, 1 Jan 2005 00:39:03 -0800, "Dan Corban"
wrote: I have a table with two columns. The first column has names of items, each item in its own row. I indent the items (using styles) if they are related to the item directly above it. I want to sort this table, keeping the indented item below the related item. I can't figure out how to do this. The indented items just get sorted normally and end up separated from the related name. An example of my table before sorting: Lamp Book Moby Dick Desk When I sort, it looks like this: Book Desk Lamp Moby Dick I want it to end up looking like this: Book Moby Dick Desk Lamp Any idea how I can accomplish this (other than manually sorting)? You might try the following (untested) process. Copy the table to an empty document; this is for safety and for non-interference. Convert the table to text. Assign the non-indented style an outline level of 1. Assign the indented style an outline level of 2. Go into Outline View. Set it to show level 1. Sort. Go back to Normal View. Everything should look right. Copy the results back to the real document. The styles ought to pick up the definition from the original document, and lose the outline levels. For paranoia, consider removing the levels from the style definitions before copying the data back. Convert back to table. Bob S |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
ALT+SHIFT+Arrow shortcut to move table rows | Tables | |||
using vba to hide rows in a table | Tables | |||
Row height problem with table in table | Tables | |||
include all cells in sorting table | Tables | |||
Can Table AutoFormat apply formatting to multiple heading rows? | Tables |