Excel常量排序 [英] Excel Constants for Sorting
本文介绍了Excel常量排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Excel VBA中使用排序过程,并希望具有根据条件将顺序更改为升序或降序的变量集。
我试过这个,但是得到一个类型不匹配的错误。
I'm using the sort procedure in Excel VBA and want to have a variable set that changes the order to ascending or descending, depending on a condition. I tried this but am getting a "type mismatch" error.
If SBF = 0 Then
S = "xlAscending"
Else: S = "xlDescending"
End If
ActiveWorkbook.Worksheets(SN(x)).sort.SortFields.Add Key:=Range( _
"B3:B" & last_cell), SortOn:=xlSortOnValues, Order:=S, DataOption:= _
xlSortNormal
推荐答案
p>这样做:
Public Enumeration, XlSortOrder, instance
Dim instance As XlSortOrder
If SBF = 0 Then
instance = xlAscending
Else: instance = xlDescending
End If
ActiveWorkbook.Worksheets(SN(x)).sort.SortFields.Add Key:=Range( _
"B3:B" & last_cell), SortOn:=xlSortOnValues, Order:=instance, DataOption:= _
xlSortNormal
这篇关于Excel常量排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文