I want to Copy and Paste Rows from one excel tab to another whenever a criteria is met. Currently, this is my code which I learnt from an online tutorial. Is there a way I can modify the code below to prevent overwriting and copying the same data twice whenever I click the button?
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
Thanks