以下是我的代码。
Sub AddExistingItemToRWP()
Dim AddRow As Integer
Dim eLastRow As Integer
AddRow = Worksheets("Recipe Workarea-Product").Range("A" & Rows.Count).End(xlUp).Row
eLastRow = Worksheets("Additional Existing Raw Mat.").Range("A" & Rows.Count).End(xlUp).Row
Dim Rng As Range
Sheets("Additional Existing Raw Mat.").Select
Set Rng = ActiveSheet.AutoFilter.Range
With Sheet12
With .Range("$A$1:K" & eLastRow)
.AutoFilter Field:=11, Criteria1:=("Y")
.SpecialCells (xlCellTypeVisible)
.Offset(1, 0) _
.Copy Destination:=Sheet8.Range("H" & AddRow + 1)
.PasteSpecial Paste = xlPasteValues
End With
End With
AutoFillCols (AddRow)
Sheets("Additional Existing Raw Mat.").Select
End Sub
.pastespecial单元格似乎不起作用。这个的正确语法是什么?
答案 0 :(得分:1)
四件事:
.SpecialCells(xlCellTypeVisible)
返回对范围的引用,但您不使用它Destination:= ...
和.PasteSpecial
与Copy
一起使用。选择一个。.PasteSpecial Paste:=xlPasteValues
而不是.PasteSpecial Paste = xlPasteValues
"Additional Existing Raw Mat."
,然后参考Sheet12
上的过滤器。你确定没错吗?<强>更新强> 如何使用Copy PasteSpecial
.Copy
Sheet8.Range("H" & AddRow + 1).PasteSpecial Paste:=xlPasteValues
答案 1 :(得分:1)
我终于解决了我的问题。这是我的代码:
Sub AddExistingItemToRWP()
Dim AddRow As Integer
Dim eLastRow As Integer
AddRow = Worksheets("Recipe Workarea-Product").Range("A" & Rows.Count).End(xlUp).Row
eLastRow = Worksheets("Additional Existing Raw Mat.").Range("A" & Rows.Count).End(xlUp).Row
Dim Rng As Range
Sheets("Additional Existing Raw Mat.").Select
Set Rng = ActiveSheet.AutoFilter.Range
With Sheet12
With .Range("$A$1:K" & eLastRow)
.AutoFilter Field:=11, Criteria1:=("Y")
.SpecialCells(xlCellTypeVisible).Select
Selection.Offset(1, 0).Copy
Sheets("Recipe Workarea-Product").Select
Range("H" & AddRow + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End With
End With
AutoFillCols (AddRow)
Sheets("Additional Existing Raw Mat.").Select
End Sub