我正在编写一个Excel宏,该宏将工作表中的数据与另一个基准工作表进行比较。目的是查看T列中的每个单元格,并将其与另一张纸的T列中的值进行比较。如果该值不存在,则另一张纸,然后复制整行并将其粘贴到另一张纸上。
编写的代码是:
Sub test()
Dim rng As Range, c As Range, cfind As Range
On Error Resume Next
Worksheets("Output").Cells.Clear
With Worksheets("Rpt_All_Plans - Baseline")
Set rng = Range(.Range("T6"), .Range("T6").End(xlDown))
For Each c In rng
With Worksheets("Rpt_All_Plans - New")
Set cfind = .Columns("T:T").Cells.Find _
(what:=c.Value, lookat:=xlWhole)
If Not (cfind Is Nothing) Then GoTo line1
c.EntireRow.Copy Worksheets("Output").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
'c.Copy Worksheets("Output").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
'c.Offset(0, 2).Copy Worksheets("Output").Cells(Rows.Count,"B").End(xlUp).Offset(1, 0)
End With 'Rpt_All_Plans - Baseline
line1:
Next c
Application.CutCopyMode = False
End With 'Rpt_All_Plans - New
End Sub
这不是真的。输出为空