怎样使用VBA背景色和拼音单列双条件排序?

2025-10-16 18:11:16

1、首先在开发工具中打开VBA编辑器

怎样使用VBA背景色和拼音单列双条件排序?

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

怎样使用VBA背景色和拼音单列双条件排序?

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

怎样使用VBA背景色和拼音单列双条件排序?

4、在模块当中输入如下代码,然后运行

Sub 单列双条件排序背景色和拼音()

 

  With ActiveWorkbook.ActiveSheet.Sort

 

  .SortFields.Clear

 

  .SortFields.Add(Application.Intersect(ActiveCell.EntireColumn,

 

    ActiveCell.CurrentRegion),xlSortOnCellColor, xlAscending)

 

  .SortOnValue.Color=ActiveCell.Interior.Color '条件一:当前单元格背景色置顶

 

  .SortFields.Add Key:=Application.Intersect(ActiveCell.EntireColumn,

 

      ActiveCell.CurrentRegion),SortOn:=xlSortOnValues, Order:=xlAscending

 

  .SetRange Application.Intersect(ActiveCell.EntireColumn,

 

      ActiveCell.CurrentRegion)

 

  .SortMethod=xlPinYin

 

          '条件二:中文排序方式为以拼音为基准

 

    .Apply

 

    End With

 

End Sub

怎样使用VBA背景色和拼音单列双条件排序?

5

怎样使用VBA背景色和拼音单列双条件排序?

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