Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Macro (2000)

    Hi,

    I created a macro to sort a table in Word by the second column. It is as follows:
    Selection.Sort ExcludeHeader:=True, FieldNumber:="Column 2", SortFieldType _
    :=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, FieldNumber2 _
    :="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
    wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
    wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
    wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID _
    :=wdEnglishUS

    I next want to delete any rows that do not have something typed in the second column. A bit stumped on that. Could anyone help with this? Thank you.

    Dorothy

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Macro (2000)

    The following is probably not the most efficient macro possible, but it should do the work for you. It assumes that the selection is inside or contains a table, and since you don't sort the first row, I have also assumed that you don't want to delete it even if there is no text in the second column.

    Sub SortAndDelete()
    Dim i As Long
    With Selection.Tables(1)
    .Sort ExcludeHeader:=True, _
    FieldNumber:="Column 2", _
    SortOrder:=wdSortOrderAscending
    For i = .Rows.Count To 2 Step -1
    If Len(.Cell(i, 2).Range.Text) = 2 Then
    .Rows(i).Delete
    End If
    Next i
    End With
    End Sub

  3. #3
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Macro (2000)

    Thank you Hans. It worked perfectly.

Posting Permissions

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