我使用宏记录器为自动过滤器创建代码。这第一次有效,但下一次,它会抛出错误“对象变量或块变量未设置”。我该如何解决这个问题?
Sheets(SheetNum + 1).Range("A7").Activate
Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select
'.Selection.AutoFilter
' Next line gives error
'ActiveWorkbook.Worksheets("Youth - PP").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Youth - PP").AutoFilter.Sort.SortFields.Add Key:= _
Range("K7:K1705"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Youth - PP").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
我在 Windows XP 中使用 Excel 2007。感谢帮助。