Excel VBAtypes不匹配工作表对象

我收到一个编译错误:

types不匹配

并不能确定问题的根源。 我相信这是简单的。 当我以ws对象作为参数调用CreateUniqueEmpList时,错误显示(VBE专门强调了recordsWS参数。

 Sub Main() Dim recordsWS As Worksheet Dim empsByJobTitles As Worksheet Application.Calculation = xlCalculationManual Application.ScreenUpdating = False Set recordsWS = Sheets("Student&GroupTransDetails") Set empsByJobTitles = Sheets("Employees") Call CreateUniqueEmpList(ByVal recordsWS, ByVal empsByJobTitles) End Sub Sub CreateUniqueEmpList(tranWS As Worksheet, empWS As Worksheet) empWS.Cells.Clear tranWS.UsedRange.AdvancedFilter Action:=xlFilterCopy, _ CopyToRange:=empsWS.Range("A1"), unique:=True empWS.Columns.AutoFit End Sub 

我做了什么:

  1. 注释掉对CreateUniqueEmpList调用,设置一个断点,并检查以确保工作表对象被设置。 它是。
  2. 从方法调用中删除了括号。 整行然后看起来像这样: CreateUNiqueEmpList ByVal recordsWS, ByVal empsByJobTitles
  3. 更改了使用Worksheets()而不是Sheets() Set两个工作表对象的方式。

任何帮助将不胜感激。