Results 1 to 5 of 5

adjust code to "cut" row instead of delete

Threaded View

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    adjust code to "cut" row instead of delete

    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
    Last edited by nigelog; 05-15-2017 at 06:42 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Delete Range that is "locked" by code allowing selection of 1 cell only.
    By Sircool1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2017, 07:05 PM
  2. [SOLVED] Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box
    By Kenny Blackwell in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 08-31-2015, 10:00 AM
  3. [SOLVED] Does a vba code "Range("A4")" change if I delete row 2?
    By thecdnmole in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 11:48 AM
  4. Formula Adjust. Need =IF"" data to remain once entered when =IF"" changes.
    By EDDYJAMES in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-02-2015, 03:44 PM
  5. [SOLVED] Code that copies row of data to another sheet based on text "Complete"/"Delete"
    By Dremzy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-20-2014, 05:51 PM
  6. Replies: 2
    Last Post: 04-20-2014, 11:18 AM
  7. [SOLVED] Script to save to folder in "v:\dept2", confirm file saved, then delete from "v:\dept1"
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2014, 11:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1