Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Apr 2001
    Location
    Arriving Somewhere but not Here
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'sort' of a challenge (Word 97 SR2)

    If I have a single table cell that contains a list of numbers in a single paragraph is there a way to sort the numbers into numerical order? They must end up in a single paragraph in a single cell again.

    stuck

  2. #2
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    St. George, Maine, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    If you numbers consist of a list like:
    22,33,55,11,44
    with a comma separator, I would simply select the list and replace the comma with a paragraph mark. Then select the list and do Table/Sort. Then restore the commas by replacing the paragraph marks with a comma.
    The above is fine for a one-time occurrence of one or 2 cells. If many cells are involved, I'll leave it to the vba gurus.

    Bob_D

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    If you have something like this:

    35

  4. #4
    5 Star Lounger
    Join Date
    Apr 2001
    Location
    Arriving Somewhere but not Here
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    Thanks for the tips, it was the conversion to paragraphs I was missing. I think I can 'sort' things out from here.

    (un)stuck
    PS I apologise for my sense of humour, it's a character fault. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    5 Star Lounger
    Join Date
    Apr 2001
    Location
    Arriving Somewhere but not Here
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    I'm back,

    I've recorded a macro that works wonderfully but for the requirement to click 'No' in response to the 'Word has finished checking the selection, do you want to check the rest of the document' dialog.

    Is there something I can add to the line...

    Selection.Find.Execute Replace:=wdReplaceAll

    to prevent this interruption? I've used Word for years but am very new to VBA so be gentle. The whole macro is below.

    (only a little bit) stuck

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = " "
    .Replacement.Text = "^p"
    .Forward = True
    .Wrap = wdFindAsk
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
    SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderAscending, _
    FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
    wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
    wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
    wdSortSeparateByDefaultTableSeparator, SortColumn:=False, CaseSensitive:= _
    False, LanguageID:=wdLanguageNone
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "^p"
    .Replacement.Text = " "
    .Forward = True
    .Wrap = wdFindAsk
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    Hi,

    Where you've got:

    .Wrap = wdFindAsk

    try changing that to:

    .Wrap = wdFindContinue

    Gary

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    or,
    .wrap = wdFindStop
    & then it won't ask or continue; it'll just sort the selection.

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    I would convert to paragraphs as well but use excel to do the sorting. Otherwise the number of digits must be equal in order to get the sort order correct. Word sorts alphabetically and so 1 to 10 sorts as 1,10,2,3,4,5,6,7,8,9.

    I don't know of a more elegant way but a macro could do it reasonably simply.
    ***** Edited by author *****
    Whoops - I guess I don't look at the sort dialog much now do I. Of course you can sort as numbers so ignore what I said.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. #9
    5 Star Lounger
    Join Date
    Apr 2001
    Location
    Arriving Somewhere but not Here
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'sort' of a challenge (Word 97 SR2)

    Phil,

    That's what I was looking for. Gary's suggestion to use ...Continue takes the default option of extending the replace outside the current selection, which doesn't do a lot for the rest of my document!

    I'm well sorted this time.

    (un) stuck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •