我希望每当满足条件时将行从一个excel选项卡复制并粘贴到另一个。目前,这是我从在线教程中学到的代码。有没有一种方法可以修改下面的代码,以防止每当我单击按钮时两次覆盖并复制相同的数据?
Private Sub CommandButton1_Click()
a = Worksheets("Results").Cells(Rows.Count, 1).End(xlUp).Row
For i = 5 To a
If Worksheets("Results").Cells(i, 29).Value = "Nutella" Then
Worksheets("Results").Rows(i).Copy
Worksheets("Nutella").Activate
b = Worksheets("Nutella").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Nutella").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Results").Activate
End If
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Results").Cells(1, 1).Select
End Sub
谢谢