Hello All
I am lost as to why my Macro won't work. The Macro actually runs and then just stays processing forever without the final result. I keep having to quit excel as it keeps going and going.
Basically I want to copy and paste anything that matches the criteria below and then delete the rows I have copied and pasted. The first IF statement works fine but it is the second IF statement for some reason where the trouble lies. Any help would be greatly appreciated.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim s1 As Worksheet, s2 As Worksheet, s3 As Worksheet
Set s1 = Sheets("Sheet 1")
Set s2 = Sheets("Sheet 2")
Set s3 = Sheets("Sheet 3")
a = s1.Cells(Rows.Count, 1).End(xlUp).Row
For i = a To 11 Step -1
b = s2.Cells(Rows.Count, 1).End(xlUp).Row
If (s1.Cells(i, 9) = "DDP" Or s1.Cells(i, 9) = "DDP 1" Or s1.Cells(i, 9) = "DDP 2" Or s1.Cells(i, 9) = "DDP 3" Or s1.Cells(i, 9) = "DDP 4") And s1.Cells(i, 33).Value > 0 Then
s1.Rows(i).Copy s2.Cells(b + 1, 1)
s1.Cells(i, 9).EntireRow.Delete
End If
If s1.Cells(i, 4).Value = "D" Then
b = s3.Cells(Rows.Count, 1).End(xlUp).Row
s1.Rows(i).Copy s3.Cells(b + 1, 1)
s1.Cells(i, 4).EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Done!"
End Sub
I am lost as to why my Macro won't work. The Macro actually runs and then just stays processing forever without the final result. I keep having to quit excel as it keeps going and going.
Basically I want to copy and paste anything that matches the criteria below and then delete the rows I have copied and pasted. The first IF statement works fine but it is the second IF statement for some reason where the trouble lies. Any help would be greatly appreciated.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim s1 As Worksheet, s2 As Worksheet, s3 As Worksheet
Set s1 = Sheets("Sheet 1")
Set s2 = Sheets("Sheet 2")
Set s3 = Sheets("Sheet 3")
a = s1.Cells(Rows.Count, 1).End(xlUp).Row
For i = a To 11 Step -1
b = s2.Cells(Rows.Count, 1).End(xlUp).Row
If (s1.Cells(i, 9) = "DDP" Or s1.Cells(i, 9) = "DDP 1" Or s1.Cells(i, 9) = "DDP 2" Or s1.Cells(i, 9) = "DDP 3" Or s1.Cells(i, 9) = "DDP 4") And s1.Cells(i, 33).Value > 0 Then
s1.Rows(i).Copy s2.Cells(b + 1, 1)
s1.Cells(i, 9).EntireRow.Delete
End If
If s1.Cells(i, 4).Value = "D" Then
b = s3.Cells(Rows.Count, 1).End(xlUp).Row
s1.Rows(i).Copy s3.Cells(b + 1, 1)
s1.Cells(i, 4).EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Done!"
End Sub