Complete VBA newbie - 6 years ago, I tried making an Excel workbook to track cases and automatically move cases from "OpenCases" to "ClosedCases" when case status changed to "Closed". I found this code on some site (maybe even here?) and just changed the triggering event to "CLOSED". It does the job of moving the row but it's inserting in the ClosedCases sheet in weird places. Sometimes row 4 sometimes row 3. It's so weird.
I gave up on the project but now we need to use it again so I'm trying to fix the issue. I tried changing the range of the destination row in name manager, but then the code stopped working.
Anyway, I need it tweaked so it automatically transfers the data to the last row available row on "Closed Cases". I also need to sort "ClosedCases" alphabetically, so every time the case is moved from Open to Closed, it should automatically sort the sheet upon closing the workbook.
Here is the code:
NOTE - In the name manager, "rngTrigger" =OpenCases!$G:$G and "rngDest" =ClosedCases!$3:$3. Row 1 has the headers but isn't named.
PLEASE PLEASE HELP!
I gave up on the project but now we need to use it again so I'm trying to fix the issue. I tried changing the range of the destination row in name manager, but then the code stopped working.
Anyway, I need it tweaked so it automatically transfers the data to the last row available row on "Closed Cases". I also need to sort "ClosedCases" alphabetically, so every time the case is moved from Open to Closed, it should automatically sort the sheet upon closing the workbook.
Here is the code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDest As Range
Set rngDest = Sheet2.Range("rngDest")
' Limit the trap area to range of cells in which completed dates are entered as defined above
If Not Intersect(Target, Sheet1.Range("rngTrigger")) Is Nothing Then
' Only trigger if the value entred is a date or is recognizable as a valid date
If UCase(Target) = "CLOSED" Then
'Ensure subsequent deletion of 'moved' row does NOT cause the Change Event to run again and get itself in a loop!
Application.EnableEvents = False
Target.EntireRow.Select
Selection.Cut
rngDest.Insert Shift:=xlDown
Selection.Delete
' Reset EnableEvents
Application.EnableEvents = True
End If
End If
End Sub
NOTE - In the name manager, "rngTrigger" =OpenCases!$G:$G and "rngDest" =ClosedCases!$3:$3. Row 1 has the headers but isn't named.
PLEASE PLEASE HELP!