In a userform I have this code deletes a driver record. I am trying to keep a copy of the record before deleting in worksheet "Removed Drivers"
'DELETE DRIVER
Private Sub btnDelDriver_Click()
If Ddtxt_1.Value = "" Then Exit Sub
Last = Cells(Rows.Count, "a").End(xlUp).Row
Set rng = Range("a1:a" & Last)
Set Rng_EMNO = Range("B1:B" & Last)
For i = Last To 2 Step -1
If rng(i).Value = DDlst_1.Column(0) And Rng_EMNO(i).Value = DDlst_1.Column(1) Then
Rows(i).EntireRow.Delete
End If
Next
End If
End Sub
I have tried this but although the message box displays the correct row number the macro does not paste the record. I can select the cell but it appears nothing is held in the clipboard. Any pointers appreciated
'DELETE DRIVER
Private Sub btnDelDriver_Click()
Dim iRow as integer
If Ddtxt_1.Value = "" Then Exit Sub
Last = Cells(Rows.Count, "a").End(xlUp).Row
Set rng = Range("a1:a" & Last)
Set Rng_EMNO = Range("B1:B" & Last)
For i = Last To 2 Step -1
If rng(i).Value = DDlst_1.Column(0) And Rng_EMNO(i).Value = DDlst_1.Column(1) Then
Rows(i).EntireRow.Cut
End If
Next
End If
With Sheets("Removed Drivers")
iRow = Worksheets("Removed Drivers").Cells(Rows.Count, 1).End(xlUp).Row + 1
MsgBox (iRow) 'displays correct row number
Set rngTarget = Worksheets("Removed Drivers").Range("A" & iRow)
rngTarget.Select
ActiveSheet.Paste
'and tried
rngTarget.Paste
End With
End Sub
Bookmarks