Copiar fila a otra hoja antes de eliminarla

Para dante amor

Buena tarde,

Te molesto con esta question.

Quiero copiar una fila de una hoja a otra antes de eliminarla, para quitarla de los datos activos y mantenerla en otra hoja como referencia.

Uso esta macro para eliminar

'Eliminar el registro
Private Sub CommandButton1_Click()

If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE REGISTRO?", vbQuestion + vbYesNo) = vbYes Then
ActiveCell.EntireRow.Delete
MsgBox " REGISTRO ELIMINADO", vbInformation´vbOKOnly
Application.ScreenUpdating = True
End If
Unload Me
End Sub

'
'Llenar los cuadro de texto con los datos del registro elegido
Private Sub userform_Initialize()

For i = 1 To 24
Me.Controls("TextBox" & i).Value = ActiveCell.Offset(0, i - 1).Value
Next i
End Sub

Pero además, suponiendo que elimino una fila y se traslada a la hoja destino en la fila 2, al volverlo a hacer el siguiente registro debe posicionarse en la fila 3 y así sucesivamente.

La hoja origen se llama "datos3" y la hoja destino se llama "respaldo"

Entonces la idea es copiar y eliminar la fila de la hoja "datos3" y pegarla en la hoja "respaldo"

1 Respuesta

Respuesta
1

Te anexo la macro para copiar y eliminar el registro seleccionado y para que se posicione en la fila 3

Private Sub CommandButton1_Click()
'Act.Por.Dante Amor
    If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE REGISTRO?", vbQuestion + vbYesNo) = vbYes Then
        f = ActiveCell.Row
        Rows(f).Cut
        Sheets("respaldo").Rows("2:2").Insert Shift:=xlDown
        Range("A3").Select
        MsgBox " REGISTRO ELIMINADO", vbInformation´vbOKOnly
        Application.ScreenUpdating = True
    End If
    Unload Me
End Sub

Saludos.Dante Amor

Hola

Bien, pero como veo en la macro siempre me va a lanzar a la fila 3 y la siguiente vez también

Range("A3").Select

y la idea es que la siguiente vez la pegue en la 4, luego el siguiente en la 5 y asi.

Además me tira error la fila que marque en negrita

Private Sub CommandButton1_Click()

If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE REGISTRO?", vbQuestion + vbYesNo) = vbYes Then
f = ActiveCell.Row
Rows(f).Cut
Sheets("respaldo").Rows("2:2").Insert shift:=xlDown
Range("A3").Select
MsgBox " REGISTRO ELIMINADO", vbInformation´vbOKOnly
Application.ScreenUpdating = True
End If
Unload Me
End Sub

Te cambio la macro, revisa que tengas una hoja con el nombre "respaldo".

La macro la debes ejecutar sobre tu hoja "datos3"

Private Sub CommandButton1_Click()
'Act.Por.Dante Amor
    If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE REGISTRO?", vbQuestion + vbYesNo) = vbYes Then
        f = ActiveCell.Row
        Rows(f).Copy
        u = Sheets("respaldo").Range("A" & Rows.Count).End(xlUp).Row + 1
        Sheets("respaldo").Range("A" & u).PasteSpecial Paste:=xlPasteValues
        Rows(f).Delete
        MsgBox " REGISTRO ELIMINADO", vbInformation + vbOKOnly
        Application.ScreenUpdating = True
    End If
    Unload Me
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas