Hello,
I have a question here.
--> I have five Command buttons in my excel sheet which is basically performing the filter and copy task. Since all of them are kind of doing the same task, I would like to merge the five Command buttons into one. Is that possible?

I would be very thankful if anyone of you could help me out in this.

Please find my code below for reference:


Private Sub CommandButton1_Click()
x = 3
Do While Cells(x, 3) <> ""
If Cells(x, 3) = "Y1" Then
Worksheets("Design Cause Notifications").Rows(x).Copy
Worksheets("For Y1").Activate
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("For Y1").Rows(erow)
End If
Worksheets("Design Cause Notifications").Activate
x = x + 1
Loop
End Sub




Private Sub CommandButton2_Click()
x = 3
Do While Cells(x, 3) <> ""
If Cells(x, 3) = "Z1" Then
Worksheets("Design Cause Notifications").Rows(x).Copy
Worksheets("For Z1").Activate
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("For Z1").Rows(erow)
End If
Worksheets("Design Cause Notifications").Activate
x = x + 1
Loop
End Sub




Private Sub CommandButton3_Click()
x = 3
Do While Cells(x, 3) <> ""
If Cells(x, 3) = "Z2" Then
Worksheets("Design Cause Notifications").Rows(x).Copy
Worksheets("For Z2").Activate
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("For Z2").Rows(erow)
End If
Worksheets("Design Cause Notifications").Activate
x = x + 1
Loop
End Sub




Private Sub CommandButton4_Click()
x = 3
Do While Cells(x, 3) <> ""
If Cells(x, 3) = "Z4" Then
Worksheets("Design Cause Notifications").Rows(x).Copy
Worksheets("For Z4").Activate
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("For Z4").Rows(erow)
End If
Worksheets("Design Cause Notifications").Activate
x = x + 1
Loop
End Sub




Private Sub CommandButton5_Click()
x = 3
Do While Cells(x, 3) <> ""
If Cells(x, 3) = "Y3" Then
Worksheets("Design Cause Notifications").Rows(x).Copy
Worksheets("For Y3").Activate
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("For Y3").Rows(erow)
End If
Worksheets("Design Cause Notifications").Activate
x = x + 1
Loop
End Sub




Kind Regards,
Antz