使用vba实现excel 列的快速排序

Sub test2()
  Dim r%, i%
  With Worksheets("sheet2")
    r = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Sort.SortFields.Clear
    .Sort.SortFields.Add Key:=.Range("A1:E1"), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="工作组,性别,姓名,年龄,地址", DataOption:=xlSortNormal
    With .Sort
      .SetRange Range("A1:E" & r)
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlLeftToRight
      .SortMethod = xlPinYin
      .Apply
    End With
  End With
End Sub
 

猜你喜欢

转载自blog.csdn.net/wsqplsh/article/details/86222023