简体   繁体   中英

I want to paste the rows for the items in Sheet1 Table 1 that are not in Sheet2 Table 2 into Sheet3 with vba

So basically I have a list of products in Table 1, Column 1 in Sheet1, I also have an updated list in Table 2, Column 1 in Sheet2. I want to be able to see what new products have been added and paste their respective rows from sheet 2 into blank sheet 3. (So basically paste whatever isn't in Sheet1 but is in Sheet 2 into a new sheet.

I tried using the Vlookup application function within my code but it's not working out so well. When I run the macro, nothing happens. Any help would be appreciated!

Sub try()
Dim Last1 As Long
Dim colPartNum As Integer

With ThisWorkbook.Sheets("NewV")
Last1 = .Cells(.Rows.Count, "A").End(xlUp).Row
colPartNum = .Range("Table2[PART NUMBER]").Column


For p = Last1 To 1 Step -1
On Error Resume Next
    If .Cells(p, colPartNum) = Application.WorksheetFunction.VLookup("Table2[PART NUMBER]", "Table1[PART NUMBER]", 1, False).Value _
    Then .Cells(p, "A").EntireRow.Copy
Worksheets("AddedParts").Range("A1").EndxlDown.Offset(1, 0).Paste
Next p
End With

End Sub

Range doesn't include a Paste method. Use PasteSpecial instead or, better yet, copy and paste in one statement using the optional Destination parameter of this method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM