View Single Post
  #5   Report Post  
Klaus Linke
 
Posts: n/a
Default

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.