[英]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.