Copie y pegue automáticamente en el cambio de celda utilizando sub privado
Pregunta
Estoy tratando de agregar una hoja de archivo a mi libro de trabajo donde se recopilan las entradas cerradas.Me gustaría que la fila de un boleto en particular se cortará de una hoja etiquetada como "boletos" y pegado en una hoja etiquetada como "archivo" una vez que su estado ha cambiado de abierto a cerrado.Me gustaría que esto suceda usando un sub privado para que suceda en el cambio de celda.El estado se encuentra en la columna 4.
Si eso es posible, supongo que será posible hacerlo al revés.Por lo tanto, si se vuelve a abrir un boleto y su estado se cambia en la hoja 'Archivo' se cortará y se pegará de nuevo en la hoja 'boletos'.
Este es el código que tenemos hasta ahora.Parece que parezcamos hacer que funcione.Cualquier ayuda sería muy apreciada.Gracias
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
Solución
Solo haciendo pequeñas enmiendas a su código actual:
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