繁体   English   中英

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

[英]unable to get the Specialcells property of the range class for xlcelltypevisible

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

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

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

Data和skuvp设置为工作表。

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

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

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

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

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

我搜索了stackoverflow和其他在线资源,但没有成功。

因此,从评论看来,问题是通过使用.Cells来解决的:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM