无法获取xlcelltypevisible范围类的Specialcells属性

我有一个Excel VBAmacros,我每周运行一次。 我有一段代码过滤出不同的数据,然后将其余的单元格复制到不同的工作表

以下是受影响代码的一部分:

dim data as worksheet dim sku vp as worksheet Set skuvp = Workbooks("weekly Brand snapshot report.xlsx").Sheets("SKU VP") set data = Workbooks("weekly Brand snapshot report.xlsx").Sheets("SKU Data") data.Range("A1").AutoFilter Field:=4, Criteria1:="Foods", Operator:=xlFilterValues data.Range("Onsales[[Product]]").SpecialCells(xlCellTypeVisible).Copy Destination:=skuvp.Range("B2") skuvp.Range("foods").Sort key1:=skuvp.Range("C1"), order1:=xlDescending, Header:=xlYes data.ShowAllData data.Range("A1").AutoFilter Field:=4, Criteria1:="Treats", Operator:=xlFilterValues data.Range("Onsales[[Product]]").SpecialCells(xlCellTypeVisible).Copy Destination:=skuvp.Range("H2") skuvp.Range("treats").Sort key1:=skuvp.Range("I1"), order1:=xlDescending, Header:=xlYes data.ShowAllData data.Range("A1").AutoFilter Field:=3, Criteria1:="Hardgoods", Operator:=xlFilterValues data.Range("B2:B16354").SpecialCells(xlCellTypeVisible).Copy Destination:=skuvp.Range("N2") skuvp.Range("hard").Sort key1:=skuvp.Range("O1"), order1:=xlDescending, Header:=xlYes data.ShowAllData data.Range("A1").AutoFilter Field:=3, Criteria1:="Specialty", Operator:=xlFilterValues data.Range("B2:B16354").SpecialCells(xlCellTypeVisible).Copy Destination:=skuvp.Range("T2") skuvp.Range("spcl").Sort key1:=skuvp.Range("U1"), order1:=xlDescending, Header:=xlYes data.ShowAllData 

数据和skuvp被设置为工作表。

这个代码在第一次运行时运行的很好。 但是,之后就开始有了一个错误。 错误出现在这一行上:

 data.Range("B2:B16354").SpecialCells(xlCellTypeVisible).Copy Destination:=skuvp.Range("N2") 

它给出的错误是“无法获取范围类的Specialcells属性”。

我原来在该代码中的范围设置表列“Onsales [[Product]]”作为范围像前面的2次我使用的代码,但将其更改为设置范围,看看是否可以解决这个问题。

当相同的基本代码早些时候工作几行时,为什么这段代码在这行上有错误?

我search了stackoverflow和其他在线来源的解决scheme没有成功。

所以,从评论看来,这个问题是通过使用.Cells解决的:

 data.Range("B2:B16354").SpecialCells(xlCellTypeVisible).Cells.Copy Destination:=skuvp.Range("N2")