Here’s my code below.
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
The .pastespecial cells seems to be not working. What is the correct syntax for this?
Four things:
.SpecialCells(xlCellTypeVisible)
returns a reference to a range, but you don’t use it- You can’t use both
Destination:= ...
and.PasteSpecial
with oneCopy
. Choose one. - You mean
.PasteSpecial Paste:=xlPasteValues
not.PasteSpecial Paste = xlPasteValues
- You activate and filter sheet
"Additional Existing Raw Mat."
, then refer to a filter onSheet12
. Are you sure thats right?
Update:
How to use Copy PasteSpecial
.Copy
Sheet8.Range("H" & AddRow + 1).PasteSpecial Paste:=xlPasteValues
Answer:
I finally got the solution to my problem. Here’s my code:
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
Tags: excel-vbaexcel, filter, vba