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)
         .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 单元格似乎无法正常工作。什么是正确的语法?

4

2 回答 2

2

我终于解决了我的问题。这是我的代码:

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
于 2013-06-26T01:49:59.620 回答
1

四件事:

  1. .SpecialCells(xlCellTypeVisible)返回对范围的引用,但您不使用它
  2. 你不能同时使用 Destination:= ....PasteSpecial一个Copy。选一个。
  3. 你的意思.PasteSpecial Paste:=xlPasteValues 不是.PasteSpecial Paste = xlPasteValues
  4. 你激活和过滤表"Additional Existing Raw Mat.",然后参考一个过滤器Sheet12。你确定那是对的吗?

更新: 如何使用 Copy PasteSpecial

.Copy 
Sheet8.Range("H" & AddRow + 1).PasteSpecial Paste:=xlPasteValues
于 2013-06-25T10:13:44.487 回答