excel 宏(VB)实现复制一列并按第二列的单元格长度排序

来源:互联网 发布:苹果手机照片传不到mac 编辑:程序博客网 时间:2024/06/07 03:32
Sub 复制排序()    Columns("B:B").Select    Selection.Copy    Columns("C:C").Select    Selection.Insert Shift:=xlToRight    Range("E1").Select    Application.CutCopyMode = False    '排序的话应该有更好的方式,直接按单元格长度排序,没时间弄    Dim t As Double    t = ActiveSheet.[A1048576].End(xlUp).Row '针对EXCEL2010            ActiveCell.FormulaR1C1 = "=LEN(RC[-2])"    Range("E1").Select    Selection.Copy    Range(Cells(t, 5), Cells(1, 5)).Select    ActiveSheet.Paste    Application.CutCopyMode = False            ActiveSheet.Sort.SortFields.Clear    ActiveSheet.Sort.SortFields.Add Key:=Range("E1"), _        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal    With ActiveSheet.Sort        .SetRange Range(Cells(1, 1), Cells(t, 5))        .Header = xlNo        .MatchCase = False        .Orientation = xlTopToBottom        .SortMethod = xlPinYin        .Apply    End With    ActiveWorkbook.Save        End Sub


0 0
原创粉丝点击