Copy and paste automatically on cell change using private sub
Question
I am trying to add an archive sheet to my workbook where closed tickets are collected. I would like the row of a particular ticket to be cut from a sheet labeled 'Tickets' and pasted into a sheet labeled 'Archive' once its status has changed from open to closed. I would like this to happen using a private sub so that it happens on cell change. The Status is found in column 4.
If that is possible im assuming it will be possible to do it the other way round too. So if a ticket is re-opened again and its status is changed in the 'Archive' sheet it will be cut and paste back into the 'Tickets' sheet.
This is the code we have so far. We can seem to get it to work. Any help would be greatly appreciated. Thank you
Private Sub Worksheet_Change (ByVal Target As Range)
If Target.Column = 4 Then
If Target.Value = "Closed" Then
R = Target.Row
Rows(R).Cut
Worksheets("Archive").Select
With ActiveSheet
lastrow = .Cells(.Rows.Count,"B").End(xlUp).Row
End With
Cells(lastrow,1).Select
Selection.Paste
End If
End If
End sub
Solution
Just making small amendments to your current code:
If Target.Column = 4 Then
If Target.Value = "Closed" Then
R = Target.Row
Rows(R).Cut
Worksheets("sheet3").Select
With ActiveSheet
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row + 1
.Cells(lastrow, 1).Select
.Paste
End With
End If
End If