Hi there!
I have a waiting list for group home admissions and code in VBA to send an entire row from one tab to another that has certain words such as "Admit" and "Cancel". When I use the drop down menu to select Admit, the screen freezes then pastes "Return" in the remaining status columns then the program crashes. What is causing this?
I have a waiting list for group home admissions and code in VBA to send an entire row from one tab to another that has certain words such as "Admit" and "Cancel". When I use the drop down menu to select Admit, the screen freezes then pastes "Return" in the remaining status columns then the program crashes. What is causing this?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Dim i As Integer
Dim b As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Lastrowb = Sheets("Admitted").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowc = Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Active").Activate
For i = 1 To Lastrow
If Cells(i, 11).Value = "Admit" Then
Rows(i).Copy Destination:=Sheets("Admitted").Rows(Lastrowb)
Lastrowb = Lastrowb + 1
End If
Next
For b = Lastrowc To 1 Step -1
If Cells(b, 11).Value = "Admit" Then
Rows(b).EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Lastrowb = Sheets("Canceled").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowc = Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Active").Activate
For i = 1 To Lastrow
If Cells(i, 11).Value = "Cancel" Then
Rows(i).Copy Destination:=Sheets("Canceled").Rows(Lastrowb)
Lastrowb = Lastrowb + 1
End If
Next
For b = Lastrowc To 1 Step -1
If Cells(b, 11).Value = "Cancel" Then
Rows(b).EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
End
End Sub