The Worksheet Change code below moves records that meet one of three criteria in column C of the sheet named “All Orgs” to another sheet named “GrntClsd”; the code then clears the moved records from the “All Orgs” sheet. I’m a relative newby to VBA, so this code may not be the most elegant, but it works.
However, I want to change the code so it fires only when the user leaves the “All Orgs” worksheet, i.e., I want to convert the code from a Worksheet Change event to a Worksheet Deactivate event. I have tried many variations and searched the forum for hours for a solution, but without success. Any help will be much appreciated. Thank you.
However, I want to change the code so it fires only when the user leaves the “All Orgs” worksheet, i.e., I want to convert the code from a Worksheet Change event to a Worksheet Deactivate event. I have tried many variations and searched the forum for hours for a solution, but without success. Any help will be much appreciated. Thank you.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Columns("C:C")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim lRow As Long
lRow = Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Range("C2:C" & lRow)
If cell.Value = "Grant Closed" Or cell.Value = "App Declined" Or cell.Value = "LOI Declined" Then
ActiveSheet.Unprotect
Range(Cells(cell.Row, "A"), Cells(cell.Row, "V")).Copy
Sheets("ClsdGrnts").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Range(Cells(cell.Row, "A"), Cells(cell.Row, "R")).ClearContents
End If
Next
Application.ScreenUpdating = True
Range("A2").Select
Application.EnableEvents = True
Application.CutCopyMode = False
End Sub