Hello all
The below Macro copy and pastes rows from my "Data" sheet to "Sheet 2" and " Sheet 3" based on the criteria below. After this macro copies and pastes i then want it to delete the same rows it copy and pasted from the original "Data" tab. Any help would be greatly appreciated.
'Copy and Paste rows that have A and B'
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
a = Worksheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
For i = 11 To a
If (Worksheets("Data").Cells(i, 9).Value = "A" Or Worksheets("Data").Cells(i, 9).Value = "B" Then
Worksheets("Data").Rows(i).Copy
Worksheets("Sheet 2").Activate
b = Worksheets("Sheet 2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet 2").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Data").Activate
End If
'Copy and Paste rows that have C'
If Worksheets("Data").Cells(i, 38).Value = "C" Then
Worksheets("Data").Rows(i).Copy
Worksheets("Sheet 3").Activate
b = Worksheets("Sheet 3").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet 3").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Data").Activate
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Done!"
End Sub
The below Macro copy and pastes rows from my "Data" sheet to "Sheet 2" and " Sheet 3" based on the criteria below. After this macro copies and pastes i then want it to delete the same rows it copy and pasted from the original "Data" tab. Any help would be greatly appreciated.
'Copy and Paste rows that have A and B'
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
a = Worksheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
For i = 11 To a
If (Worksheets("Data").Cells(i, 9).Value = "A" Or Worksheets("Data").Cells(i, 9).Value = "B" Then
Worksheets("Data").Rows(i).Copy
Worksheets("Sheet 2").Activate
b = Worksheets("Sheet 2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet 2").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Data").Activate
End If
'Copy and Paste rows that have C'
If Worksheets("Data").Cells(i, 38).Value = "C" Then
Worksheets("Data").Rows(i).Copy
Worksheets("Sheet 3").Activate
b = Worksheets("Sheet 3").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet 3").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Data").Activate
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Done!"
End Sub