Easy Cut & Paste to duplicate sheet

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
My company uses a lot of spreadsheets where there are 2 tabs; one for "active" and another for "completed". The user typically will cut and paste a completed row from the active sheet to the completed sheet. Both sheets have exact same headers.

To automate this, I created code so that the user merely needs to double click on the row to "move" it to the next blank row on the "completed" tab.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim lastrow As Long
Dim nextrow As Long
Dim sselrow As String
Dim rselrow As String
On Error Resume Next
lastrow = 1
lastrow = Sheet2.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
Resume Next
Cancel = True
sselrow = ActiveCell.Row & ":" & ActiveCell.Row
Rows(sselrow).Select
    Selection.Cut
    Sheet2.Select
    rselrow = lastrow & ":" & lastrow
    Sheet2.Rows(rselrow).Select
    ActiveSheet.Paste
    Sheet1.Select
    Sheet1.Rows(sselrow).Select
    Selection.Delete Shift:=xlUp
End Sub

The above code would go ONLY on the "active" tab by right clicking the tab and VIEW CODE - paste it in.
Keep in mind it assumes "active" tab is Sheet1 and "completed" tab is Sheet2. Modify as needed.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi

I think this might do roughly what you want it to do, see how it goes and if it needs a tweak post back and I'll amend it.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim lastrow As Long
Dim r As Range
With Application
    .ScreenUpdating = False
        lastrow = Sheets("complete").Range("A" & Rows.Count).End(xlUp).Row + 1
        With ActiveCell
            .EntireRow.Copy Sheets("complete").Range("A" & lastrow)
            .EntireRow.Delete xlUp
        End With
        Cancel = True
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,810
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top