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  

Sort a MS Word table in two different ways



 
 
Thread Tools Display Modes
  #1  
Old January 25th, 2008, 01:43 AM posted to microsoft.public.word.tables
Algelina
external usenet poster
 
Posts: 2
Default Sort a MS Word table in two different ways

Hi !!

I am trying to figure out how to do some fancy sorting using macros in
MS WORD.

I have a table with exactly 10 rows with a "Team" column of A
and more rows with a "Team" column of B
and more rows with a "Team column of X

I would like to sort this table using macros so that:

Rows with Team A are sorted by grade then name
Rows with Team B are sorted only by name

I hope to take this sorted info and put it into a mail merged roster
file.

Any ideas? Please be gentle with me, I am new to macros.

AL
  #2  
Old January 25th, 2008, 03:07 AM posted to microsoft.public.word.tables
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Sort a MS Word table in two different ways

I've just done something rather like this, as it happens. What I would
suggest would be first sorting the table into A and B, then temporarily
splitting the table between A and B and sorting each separately as needed,
then rejoining the table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Algelina" wrote in message
...
Hi !!

I am trying to figure out how to do some fancy sorting using macros in
MS WORD.

I have a table with exactly 10 rows with a "Team" column of A
and more rows with a "Team" column of B
and more rows with a "Team column of X

I would like to sort this table using macros so that:

Rows with Team A are sorted by grade then name
Rows with Team B are sorted only by name

I hope to take this sorted info and put it into a mail merged roster
file.

Any ideas? Please be gentle with me, I am new to macros.

AL



  #3  
Old January 25th, 2008, 07:38 AM posted to microsoft.public.word.tables
Tony Jollans
external usenet poster
 
Posts: 1,297
Default Sort a MS Word table in two different ways

You don't need to split the table to do this.After sorting on A,B,X,etc.
just select the A rows and sort again on the second column; then select the
B rows and sort those, etc.

--
Enjoy,
Tony

"Suzanne S. Barnhill" wrote in message
...
I've just done something rather like this, as it happens. What I would
suggest would be first sorting the table into A and B, then temporarily
splitting the table between A and B and sorting each separately as needed,
then rejoining the table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Algelina" wrote in message
...
Hi !!

I am trying to figure out how to do some fancy sorting using macros in
MS WORD.

I have a table with exactly 10 rows with a "Team" column of A
and more rows with a "Team" column of B
and more rows with a "Team column of X

I would like to sort this table using macros so that:

Rows with Team A are sorted by grade then name
Rows with Team B are sorted only by name

I hope to take this sorted info and put it into a mail merged roster
file.

Any ideas? Please be gentle with me, I am new to macros.

AL




  #4  
Old January 25th, 2008, 03:46 PM posted to microsoft.public.word.tables
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Sort a MS Word table in two different ways

Ah, I'm not sure I realized you could sort part of a table that way, but it
makes sense.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Tony Jollans" My forename at my surname dot com wrote in message
...
You don't need to split the table to do this.After sorting on A,B,X,etc.
just select the A rows and sort again on the second column; then select
the B rows and sort those, etc.

--
Enjoy,
Tony

"Suzanne S. Barnhill" wrote in message
...
I've just done something rather like this, as it happens. What I would
suggest would be first sorting the table into A and B, then temporarily
splitting the table between A and B and sorting each separately as
needed, then rejoining the table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Algelina" wrote in message
...
Hi !!

I am trying to figure out how to do some fancy sorting using macros in
MS WORD.

I have a table with exactly 10 rows with a "Team" column of A
and more rows with a "Team" column of B
and more rows with a "Team column of X

I would like to sort this table using macros so that:

Rows with Team A are sorted by grade then name
Rows with Team B are sorted only by name

I hope to take this sorted info and put it into a mail merged roster
file.

Any ideas? Please be gentle with me, I am new to macros.

AL







  #5  
Old January 25th, 2008, 08:42 PM posted to microsoft.public.word.tables
Algelina
external usenet poster
 
Posts: 2
Default Sort a MS Word table in two different ways

Yes, I was able to do that also. But I would like to create a macro
that will do that. How can I create a macro that will do that?

Thanks



On Jan 25, 2:38 am, "Tony Jollans" My forename at my surname dot com
wrote:
You don't need to split the table to do this.After sorting on A,B,X,etc.
just select the A rows and sort again on the second column; then select the
B rows and sort those, etc.

--
Enjoy,
Tony

"Suzanne S. Barnhill" wrote in l...

I've just done something rather like this, as it happens. What I would
suggest would be first sorting the table into A and B, then temporarily
splitting the table between A and B and sorting each separately as needed,
then rejoining the table.


--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA


"Algelina" wrote in message
...
Hi !!


I am trying to figure out how to do some fancy sorting using macros in
MS WORD.


I have a table with exactly 10 rows with a "Team" column of A
and more rows with a "Team" column of B
and more rows with a "Team column of X


I would like to sort this table using macros so that:


Rows with Team A are sorted by grade then name
Rows with Team B are sorted only by name


I hope to take this sorted info and put it into a mail merged roster
file.


Any ideas? Please be gentle with me, I am new to macros.


AL

  #6  
Old January 26th, 2008, 11:45 AM posted to microsoft.public.word.tables
Tony Jollans
external usenet poster
 
Posts: 1,297
Default Sort a MS Word table in two different ways

Here is some code that should do what you want:

Sub MultiSort()

Dim TableHasHeadings As Boolean
TableHasHeadings = False ' Set to True if you do have headings

Dim RowNo1 As Long, RowNo2 As Long
With ActiveDocument.Tables(1)
.Range.Sort ExcludeHeader:=TableHasHeadings, _
Fieldnumber:="Column 1"
RowNo1 = 1 - TableHasHeadings
Do While RowNo1 = .Rows.Count
RowNo2 = RowNo1 + 1
Do While RowNo2 = .Rows.Count
If .Cell(RowNo1, 1).Range _
.Cell(RowNo2, 1).Range Then Exit Do
RowNo2 = RowNo2 + 1
Loop
RowNo2 = RowNo2 - 1
If RowNo2 RowNo1 Then
Select Case ActiveDocument.Range( _
.Cell(RowNo1, 1).Range.Start, _
.Cell(RowNo1, 1).Range.End - 1)
Case "A"
ActiveDocument.Range(.Rows(RowNo1).Range.Start, _
.Rows(RowNo2).Range.End) _
.Sort Fieldnumber:="Column 2", _
Fieldnumber2:="Column 3"
Case "B"
ActiveDocument.Range(.Rows(RowNo1).Range.Start, _
.Rows(RowNo2).Range.End) _
.Sort Fieldnumber:="Column 3"
End Select
End If
RowNo1 = RowNo2 + 1
Loop
End With

End Sub

If you don't know what to do with this see
http://www.gmayor.com/installing_macro.htm

You may have to change it slightly, depending on:

(a) whether you have column headings in your table - see the line near the
beginning with the comment

(b) I have assumed "Team" is in column 1 of your table - if not you will
have to change "Column !" in the first Sort to "Column whatever". Yopu will
also have to change all the references ".Cell(RowNo,1)" to ".Cell(RowNo,n)"
where n is the actual column number (and RowNo may be either RowNo1 or
RowNo2)

(c) I have also assumed that "Grade" is in column 2 and "Name" is in column
3. If not, you will have to change the column numbers in the two Sorts at
the end

(d) If you want to do something different with team "X" (or any other) you
will have to add an extra "Case" and another Sort, as per the existing two.

If you need any more help, do come back.

--
Enjoy,
Tony

"Algelina" wrote in message
...
Yes, I was able to do that also. But I would like to create a macro
that will do that. How can I create a macro that will do that?

Thanks



On Jan 25, 2:38 am, "Tony Jollans" My forename at my surname dot com
wrote:
You don't need to split the table to do this.After sorting on A,B,X,etc.
just select the A rows and sort again on the second column; then select
the
B rows and sort those, etc.

--
Enjoy,
Tony

"Suzanne S. Barnhill" wrote in
l...

I've just done something rather like this, as it happens. What I would
suggest would be first sorting the table into A and B, then temporarily
splitting the table between A and B and sorting each separately as
needed,
then rejoining the table.


--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA


"Algelina" wrote in message
...
Hi !!


I am trying to figure out how to do some fancy sorting using macros in
MS WORD.


I have a table with exactly 10 rows with a "Team" column of A
and more rows with a "Team" column of B
and more rows with a "Team column of X


I would like to sort this table using macros so that:


Rows with Team A are sorted by grade then name
Rows with Team B are sorted only by name


I hope to take this sorted info and put it into a mail merged roster
file.


Any ideas? Please be gentle with me, I am new to macros.


AL


 




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


All times are GMT +1. The time now is 07:35 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.