应用场景 对职工信息按照学历排序(适用于Excel 2007及以上版本) 知识要点 1:Sort.SortFields.Add 方法 创建新的排序字段,并返回一个 SortFields 对象。 2:Sort.SortFields.Clear 方法,清除存储的排序状态 Sub 按学历排序() ActiveSheet.Sort.SortFields.Clear '清除sort对象的字段 '添加新的排序字段 ActiveSheet.Sort.SortFields.Add Key:=Range('C2:C' & Cells(Rows.Count, 3).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, _ CustomOrder:='大学,高中,初中,小学', DataOption:=xlSortNormal With ActiveSheet.Sort .SetRange Range('A2:D' & Cells(Rows.Count, 3).End(xlUp).Row) '指定排序区域 .Header = xlNo '不要表头 .Apply '执行排序 End With End Sub |
|