怎样使用VBA双条件排序:首列升序、次列降序?
1、首先在开发工具中打开VBA编辑器

2、在单元格区域当中输入一些内容作为例子

3、在VBA编辑器中插入模块

4、在模块当中输入如下代码,然后运行
Sub 双条件排序首列升序次列降序()
With ActiveWorkbook.ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Application.Intersect(ActiveCell.EntireColumn,
ActiveCell.CurrentRegion),SortOn:=xlSortOnValues, Order:=
xlAscending
'首列按数值升序排序
.SortFields.Add Key:=Application.Intersect(ActiveCell.Offset(0, 1)
.EntireColumn, ActiveCell.CurrentRegion),SortOn:=xlSortOnValues,
Order:=xlDescending, DataOption:=xlSortNormal '次列以笔画为基准降序排序
.SetRange Application.Intersect(Selection.CurrentRegion, Selection.
CurrentRegion.Offset(1, 0))
.SortMethod=xlStroke
.Apply
End With
End Sub

5、选中B5单元格(光标位置很重要,激活不同列有不同结果),用快捷键Alt+F8调出运行宏窗口,然后单击“执行”按钮,B列数据除首行外均按数值升序排列

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:194
阅读量:24
阅读量:137
阅读量:89
阅读量:51