Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Macro to Sort 5 Column Table

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners
View previous topic :: View next topic  
Author Message
Alan in NJ
Guest





PostPosted: Mon Nov 12, 2007 7:02 pm    Post subject: Macro to Sort 5 Column Table Reply with quote

Rarely writing macros, I forgot how to deal with the pesky end-of-cell mark.
I need a macro to simply alphabetically sort a five-column table. Some
quick help would be appreciated.

Alan
Back to top
Google
Sponsor





PostPosted: Mon Nov 12, 2007 7:02 pm    Post subject: Advertisement

Back to top
Doug Robbins - Word MVP
Guest





PostPosted: Mon Nov 12, 2007 7:28 pm    Post subject: Re: Macro to Sort 5 Column Table Reply with quote

You don't need to worry about the end of cell marker. If you type Sort into
the Visual Basic Editor and press F1, you will get the following information

Word Developer Reference
Table.Sort Method
Sorts the specified table.
expression.Sort(ExcludeHeader, FieldNumber, SortFieldType, SortOrder,
FieldNumber2, SortFieldType2, SortOrder2, FieldNumber3, SortFieldType3,
SortOrder3, CaseSensitive, BidiSort, IgnoreThe, IgnoreKashida,
IgnoreDiacritics, IgnoreHe, LanguageID)

expression Required. A variable that represents a Table object.

Parameters

Name Required/Optional Data Type Description
ExcludeHeader Optional Variant True to exclude the first row from the
sort operation. The default value is False.
FieldNumber Optional Variant The first field by which to sort.
Microsoft Word sorts by FieldNumber, then by FieldNumber2, and then by
FieldNumber3.
SortFieldType Optional Variant The sort type for FieldNumber. Can be
one of the WdSortFieldType constants. Some of these constants may not be
available to you, depending on the language support (U.S. English, for
example) that you have selected or installed. The default value is
wdSortFieldAlphanumeric.
SortOrder Optional Variant The sorting order to use when sorting
FieldNumber. Can be a WdSortOrder constant.
FieldNumber2 Optional Variant The second field by which to sort.
SortFieldType2 Optional Variant The sort type for FieldNumber2. Can be
one of the WdSortFieldType constants. Some of these constants may not be
available to you, depending on the language support (U.S. English, for
example) that you have selected or installed. The default value is
wdSortFieldAlphanumeric.
SortOrder2 Optional Variant The sorting order to use when sorting
FieldNumber2. Can be one WdSortOrder constant.
FieldNumber3 Optional Variant The third field by which to sort.
SortFieldType3 Optional Variant The sort type for FieldNumber3. Can be
one of the WdSortFieldType constants. Some of these constants may not be
available to you, depending on the language support (U.S. English, for
example) that you have selected or installed. The default value is
wdSortFieldAlphanumeric.
SortOrder3 Optional Variant The sorting order to use when sorting
FieldNumber3. Can be one WdSortOrder constant.
CaseSensitive Optional Variant True to sort with case sensitivity. The
default value is False.
BidiSort Optional Variant True to sort based on right-to-left language
rules. This argument may not be available to you, depending on the language
support (U.S. English, for example) that you've selected or installed.
IgnoreThe Optional Variant True to ignore the Arabic character alef
lam when sorting right-to-left language text. This argument may not be
available to you, depending on the language support (U.S. English, for
example) that you've selected or installed.
IgnoreKashida Optional Variant True to ignore kashidas when sorting
right-to-left language text. This argument may not be available to you,
depending on the language support (U.S. English, for example) that you've
selected or installed.
IgnoreDiacritics Optional Variant True to ignore bidirectional control
characters when sorting right-to-left language text. This argument may not
be available to you, depending on the language support (U.S. English, for
example) that you've selected or installed.
IgnoreHe Optional Variant True to ignore the Hebrew character he when
sorting right-to-left language text. This argument may not be available to
you, depending on the language support (U.S. English, for example) that you've
selected or installed.
LanguageID Optional Variant Specifies the sorting language. Can be one
of the WdLanguageID constants. Refer to the Object Browser for a list of the
WdLanguageID constants.

Example


This example sorts the first table in the active document, excluding the
heading row.

Visual Basic for Applications
Sub NewTableSort()
ActiveDocument.Tables(1).Sort ExcludeHeader:=True
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Alan in NJ" <devildad77@comcast.net> wrote in message
news:eYnnX6VJIHA.5328@TK2MSFTNGP05.phx.gbl...
Quote:
Rarely writing macros, I forgot how to deal with the pesky end-of-cell
mark. I need a macro to simply alphabetically sort a five-column table.
Some quick help would be appreciated.

Alan
Back to top
Alan in NJ
Guest





PostPosted: Mon Nov 12, 2007 7:45 pm    Post subject: Re: Macro to Sort 5 Column Table Reply with quote

Thanks Doug. I'll give it a try.

alan
"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:Oi9D3IWJIHA.1208@TK2MSFTNGP05.phx.gbl...
Quote:
You don't need to worry about the end of cell marker. If you type Sort
into the Visual Basic Editor and press F1, you will get the following
information

Word Developer Reference
Table.Sort Method
Sorts the specified table.
expression.Sort(ExcludeHeader, FieldNumber, SortFieldType, SortOrder,
FieldNumber2, SortFieldType2, SortOrder2, FieldNumber3, SortFieldType3,
SortOrder3, CaseSensitive, BidiSort, IgnoreThe, IgnoreKashida,
IgnoreDiacritics, IgnoreHe, LanguageID)

expression Required. A variable that represents a Table object.

Parameters

Name Required/Optional Data Type Description
ExcludeHeader Optional Variant True to exclude the first row from the
sort operation. The default value is False.
FieldNumber Optional Variant The first field by which to sort.
Microsoft Word sorts by FieldNumber, then by FieldNumber2, and then by
FieldNumber3.
SortFieldType Optional Variant The sort type for FieldNumber. Can be
one of the WdSortFieldType constants. Some of these constants may not be
available to you, depending on the language support (U.S. English, for
example) that you have selected or installed. The default value is
wdSortFieldAlphanumeric.
SortOrder Optional Variant The sorting order to use when sorting
FieldNumber. Can be a WdSortOrder constant.
FieldNumber2 Optional Variant The second field by which to sort.
SortFieldType2 Optional Variant The sort type for FieldNumber2. Can
be one of the WdSortFieldType constants. Some of these constants may not
be available to you, depending on the language support (U.S. English, for
example) that you have selected or installed. The default value is
wdSortFieldAlphanumeric.
SortOrder2 Optional Variant The sorting order to use when sorting
FieldNumber2. Can be one WdSortOrder constant.
FieldNumber3 Optional Variant The third field by which to sort.
SortFieldType3 Optional Variant The sort type for FieldNumber3. Can
be one of the WdSortFieldType constants. Some of these constants may not
be available to you, depending on the language support (U.S. English, for
example) that you have selected or installed. The default value is
wdSortFieldAlphanumeric.
SortOrder3 Optional Variant The sorting order to use when sorting
FieldNumber3. Can be one WdSortOrder constant.
CaseSensitive Optional Variant True to sort with case sensitivity.
The default value is False.
BidiSort Optional Variant True to sort based on right-to-left
language rules. This argument may not be available to you, depending on
the language support (U.S. English, for example) that you've selected or
installed.
IgnoreThe Optional Variant True to ignore the Arabic character alef
lam when sorting right-to-left language text. This argument may not be
available to you, depending on the language support (U.S. English, for
example) that you've selected or installed.
IgnoreKashida Optional Variant True to ignore kashidas when sorting
right-to-left language text. This argument may not be available to you,
depending on the language support (U.S. English, for example) that you've
selected or installed.
IgnoreDiacritics Optional Variant True to ignore bidirectional
control characters when sorting right-to-left language text. This argument
may not be available to you, depending on the language support (U.S.
English, for example) that you've selected or installed.
IgnoreHe Optional Variant True to ignore the Hebrew character he when
sorting right-to-left language text. This argument may not be available to
you, depending on the language support (U.S. English, for example) that
you've selected or installed.
LanguageID Optional Variant Specifies the sorting language. Can be
one of the WdLanguageID constants. Refer to the Object Browser for a list
of the WdLanguageID constants.

Example


This example sorts the first table in the active document, excluding the
heading row.

Visual Basic for Applications
Sub NewTableSort()
ActiveDocument.Tables(1).Sort ExcludeHeader:=True
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Alan in NJ" <devildad77@comcast.net> wrote in message
news:eYnnX6VJIHA.5328@TK2MSFTNGP05.phx.gbl...
Rarely writing macros, I forgot how to deal with the pesky end-of-cell
mark. I need a macro to simply alphabetically sort a five-column table.
Some quick help would be appreciated.

Alan


Back to top
Alan in NJ
Guest





PostPosted: Mon Nov 12, 2007 9:32 pm    Post subject: Re: Macro to Sort 5 Column Table Reply with quote

Really strange: in Word 2002 I can't get even the example (NewTableSort) to
work. If I put in a sample one row one column table with a bunch of row, it
sorts a row or two, deleted some rows and moves several individual letters
to the right of the table outside the border. Any ideas would be
appreaciated.
"Alan in NJ" <devildad77@comcast.net> wrote in message
news:eYnnX6VJIHA.5328@TK2MSFTNGP05.phx.gbl...
Quote:
Rarely writing macros, I forgot how to deal with the pesky end-of-cell
mark. I need a macro to simply alphabetically sort a five-column table.
Some quick help would be appreciated.

Alan
Back to top
Russ
Guest





PostPosted: Wed Nov 14, 2007 7:04 pm    Post subject: Re: Macro to Sort 5 Column Table Reply with quote

Alan,
I think you are mixing up the terminology. Doug's info will sort table rows.
Are you trying to sort paragraphs or lines inside table cell(s)?

Quote:
Really strange: in Word 2002 I can't get even the example (NewTableSort) to
work. If I put in a sample one row one column table with a bunch of row, it
sorts a row or two, deleted some rows and moves several individual letters
to the right of the table outside the border. Any ideas would be
appreaciated.
"Alan in NJ" <devildad77@comcast.net> wrote in message
news:eYnnX6VJIHA.5328@TK2MSFTNGP05.phx.gbl...
Rarely writing macros, I forgot how to deal with the pesky end-of-cell
mark. I need a macro to simply alphabetically sort a five-column table.
Some quick help would be appreciated.

Alan




--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
Back to top
Alan in NJ
Guest





PostPosted: Thu Nov 15, 2007 9:25 pm    Post subject: Re: Macro to Sort 5 Column Table Reply with quote

Yes, I am trying to sort lines of text in a table cell. Any help would be
GREATLY appreciated.
Alan
"Russ" <drsN0SPAMmikle@hotmailD0Tcom.INVALID> wrote in message
news:C360B0D2.1F203%drsN0SPAMmikle@hotmailD0Tcom.INVALID...
Quote:
Alan,
I think you are mixing up the terminology. Doug's info will sort table
rows.
Are you trying to sort paragraphs or lines inside table cell(s)?

Really strange: in Word 2002 I can't get even the example (NewTableSort)
to
work. If I put in a sample one row one column table with a bunch of row,
it
sorts a row or two, deleted some rows and moves several individual
letters
to the right of the table outside the border. Any ideas would be
appreaciated.
"Alan in NJ" <devildad77@comcast.net> wrote in message
news:eYnnX6VJIHA.5328@TK2MSFTNGP05.phx.gbl...
Rarely writing macros, I forgot how to deal with the pesky end-of-cell
mark. I need a macro to simply alphabetically sort a five-column table.
Some quick help would be appreciated.

Alan




--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
Back to top
Alan in NJ
Guest





PostPosted: Fri Nov 16, 2007 12:51 am    Post subject: Re: Macro to Sort 5 Column Table Reply with quote

Russ:Found one of your old posts and was able to figure it out.
Thanks.
alan
"Russ" <drsN0SPAMmikle@hotmailD0Tcom.INVALID> wrote in message
news:C360B0D2.1F203%drsN0SPAMmikle@hotmailD0Tcom.INVALID...
Quote:
Alan,
I think you are mixing up the terminology. Doug's info will sort table
rows.
Are you trying to sort paragraphs or lines inside table cell(s)?

Really strange: in Word 2002 I can't get even the example (NewTableSort)
to
work. If I put in a sample one row one column table with a bunch of row,
it
sorts a row or two, deleted some rows and moves several individual
letters
to the right of the table outside the border. Any ideas would be
appreaciated.
"Alan in NJ" <devildad77@comcast.net> wrote in message
news:eYnnX6VJIHA.5328@TK2MSFTNGP05.phx.gbl...
Rarely writing macros, I forgot how to deal with the pesky end-of-cell
mark. I need a macro to simply alphabetically sort a five-column table.
Some quick help would be appreciated.

Alan




--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum