如何从过滤范围复制粘贴特殊细胞

时间:2013-06-25 09:51:37

标签: excel-vba vba excel

以下是我的代码。

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单元格似乎不起作用。这个的正确语法是什么?

2 个答案:

答案 0 :(得分:1)

四件事:

  1. .SpecialCells(xlCellTypeVisible)返回对范围的引用,但您不使用它
  2. 您不能将{em> Destination:= ....PasteSpecialCopy一起使用。选择一个。
  3. 您的意思是.PasteSpecial Paste:=xlPasteValues而不是.PasteSpecial Paste = xlPasteValues
  4. 您激活并过滤工作表"Additional Existing Raw Mat.",然后参考Sheet12上的过滤器。你确定没错吗?
  5. <强>更新 如何使用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