我有一个宏,当我按下按钮时,我将数据粘贴到另一张纸上,但它也允许重复输入。我不知道如何阻止复制的重复条目。
Sub Register_Copy()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Set copySheet = Worksheets("RACF ID")
Set pasteSheet = Worksheets("Sheet1")
copySheet.Range("C4").Copy
pasteSheet.Cells(Rows.count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
copySheet.Range("B6").Copy
pasteSheet.Cells(Rows.count, 1).End(xlUp).Offset(0, 1).PasteSpecial xlPasteValues
copySheet.Range("C6").Copy
pasteSheet.Cells(Rows.count, 1).End(xlUp).Offset(0, 2).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
如果您避免复制和粘贴,它会更快,但您将该值记录为String
变量,然后在列中写入此字符串变量。因此,您还可以在写入之前检查该列中是否存在该变量。
Public Sub TestMe()
Dim newValue As Variant
newValue = copysheet.Range("C4").Value2
With pastesheet
If IsError(WorksheetFunction.Match(newValue, .Columns(3), 0)) Then
.Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0) = newValue
End If
End With
End Sub