A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Sorting a table while keeping some related rows together



 
 
Thread Tools Display Modes
  #1  
Old January 1st, 2005, 08:39 AM
Dan Corban
external usenet poster
 
Posts: n/a
Default Sorting a table while keeping some related rows together

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  
Old January 1st, 2005, 04:05 PM
Jay Freedman
external usenet poster
 
Posts: n/a
Default

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  
Old January 1st, 2005, 04:55 PM
Dan Corban
external usenet poster
 
Posts: n/a
Default

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  
Old January 1st, 2005, 07:25 PM
Jay Freedman
external usenet poster
 
Posts: n/a
Default

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  
Old January 3rd, 2005, 05:51 PM
Klaus Linke
external usenet poster
 
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.




  #6  
Old January 6th, 2005, 03:01 PM
Dan Corban
external usenet poster
 
Posts: n/a
Default

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  
Old January 10th, 2005, 08:52 PM
Klaus Linke
external usenet poster
 
Posts: n/a
Default

Hi Dan,

You're right, it doesn't work for me in Word2003 either.
Not sure whether I was hallicunating, or whether I did somehow get it to work in the past.

Sorry!!

Plan C (counting Jay's method) might be:
Convert the table to tab-delimited text (...hope that's possible...), and then replace the paragraph marks in front of the paras
that should sort with the preceeding paragraphs with line breaks (Shift-Return).

If you can locate the rows that should sort with the preceeding "rows" with "Find/Replace", you can achieve that with two
"Find/Replaces":

-- Say they are in style "DontSort", then search for that style, check "Match wildcards", and put [!^13]@^13 in "Find what".
Replace with $$$^&.

-- Then replace ^p$$$ with ^l$$$.

If you finally have
E
D

B

then you get after sorting
B

E
D

and can replace the *l*ine breaks (^l) with *p*aragraph marks (^p) again.

Klaus


Dan Corban wrote:
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.




  #8  
Old January 20th, 2005, 07:31 PM
Bob S
external usenet poster
 
Posts: n/a
Default

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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate data Rob Green Database Design 3 November 7th, 2004 03:08 AM
Repeat Records - Please Help? Repeat records Running & Setting Up Queries 9 September 29th, 2004 05:29 PM
Semicolon delimited text query help Al Guerra Running & Setting Up Queries 3 August 12th, 2004 11:50 AM
change a table to 3 columns only (Rows instead of Table) Mo General Discussion 2 August 7th, 2004 10:16 PM
Pivot Table Too Many Rows Or Colums Joe Worksheet Functions 0 October 9th, 2003 05:17 PM


All times are GMT +1. The time now is 07:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.