【发布时间】:2017-12-10 20:32:38
【问题描述】:
我写了以下函数
Public Function sorting(WS As Worksheets, Col As Range, Rng As Range, Sort_Order As XlSortOrder)
Application.ScreenUpdating = False
With WS
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Col, SortOn:=xlSortOnValues, Order:=Sort_Order, DataOption:=xlSortNormal
With .Sort
.SetRange Rng
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Application.ScreenUpdating = True
End Function
现在我正在尝试根据函数运行以下代码。
Private Sub cmbCareerPath_Change()
Application.ScreenUpdating = True
Set WS = Worksheets("FindPath")
Set Col = WS.Range("D:D")
Set Rng = WS.Range("A:Z")
Call sorting(WS, Col, Rng, xlAscending)
Application.ScreenUpdating = False
End Sub
但是,当我运行我的 Sub 时,我得到了编译错误:
ByRef argument type mismatch
在 WS 上的下面一行。
调用排序(WS, Column, Rng, xlAscending)
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
WS是一个工作表对象。您将其传递给 WorkSheets 集合。在您的子中,将WS as WorkSheets更改为WS as WorkSheet。