vba Excel 2003 中的 ActiveSheet.AutoFilter.Sort.SortFields.Clear

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22044970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:52:27  来源:igfitidea点击:

ActiveSheet.AutoFilter.Sort.SortFields.Clear in Excel 2003

vbaexcel-2003

提问by brWHigino

I have a macro that works in Excel 2013, but the following part of the code breaks when running the macro in Excel 2003:

我有一个可在 Excel 2013 中运行的宏,但在 Excel 2003 中运行该宏时,以下部分代码会中断:

Sheets("dados").Select
Range("A1").AutoFilter Field:=6, Criteria1:="<>"
ActiveSheet.AutoFilter.Sort.SortFields.Clear
ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.AutoFilter.Sort.Apply

I wasn't able to find a clear reason why it is breaking. I read people mentioning the problem is the Sort object, but didn't find any replacement options. Is there a replacement for this filtering procedure which would work in Excel 2003?

我无法找到它崩溃的明确原因。我读到有人提到问题是 Sort 对象,但没有找到任何替换选项。是否有可以在 Excel 2003 中工作的过滤程序的替代品?

I appreciate any help.

我很感激任何帮助。

回答by Dmitry Pavliv

Try this one:

试试这个:

With ThisWorkbook.Sheets("dados")
    .Range("A1").AutoFilter Field:=6, Criteria1:="<>"

    .Range("A1").CurrentRegion.Sort Key1:=.Range("A1"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, DataOption1:=xlSortNormal
End With