Macro needed for transferring rows to new worksheet

Fraserj

Board Regular
Joined
Nov 29, 2015
Messages
63
Hi, I'm struggling with Macros abit and I am wondering if any of you people could help me?

I have 2 worksheets "Sheet1" & "Sheet2"

I have done a small table below just as an example.
Worksheet one is the sheet that I fill in.. I need a Macro that automatically transfers a whole row once any cell in Row "R" has "COMPLETED" in the cell.
I want this row to be Cut and Pasted into the next available Row in Sheet2.
Once the Row is Transferred I need the other Rows in "Sheet1" to move up, rather than leaving an empty row at the top of the work sheet.
PQR
File Sent BackReference NumberComplete?
Yesdadkslmf
YesfjdfnCOMPLETED
YeskjfdsCOMPLETED

<tbody>
</tbody>

Is this possible, if so can somebody help me?

Also If it is possible, is it also possible to undo the Macro if COMPLETED is typed by mistake, or in the wrong Row, so it will transfer back to worksheet 1
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
No if you had the macro delete the row you cannot undo that action.
I normally suggest we you a double click event. That means in you double click on any row in column "R" it will copy over your data and then delete the row. It's hard to accidently double click a cell.
Would that option work for you?
 
Upvote 0
If your willing to use my suggestion. Any time you double click on a cell in column "R" this row of data will be copied over to sheet(2) on the first empty row. And then the script will delete that row on sheet(1)
Be sure and note Sheet(1) is the sheet in the far left position on your tab menu and sheet (2) is the next sheet to the right on the tab bar.
To install this code:

Right-click on the sheet (1) tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Not Intersect(Target, Range("R:R")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim Lastrow As Long
Lastrow = Sheets(2).Cells(Rows.Count, "R").End(xlUp).Row + 1
Rows(Target.Row).Copy Destination:=Sheets(2).Rows(Lastrow)
Rows(Target.Row).EntireRow.Delete
End If
End Sub
 
Upvote 0
If your willing to use my suggestion. Any time you double click on a cell in column "R" this row of data will be copied over to sheet(2) on the first empty row. And then the script will delete that row on sheet(1)
Be sure and note Sheet(1) is the sheet in the far left position on your tab menu and sheet (2) is the next sheet to the right on the tab bar.
To install this code:

Right-click on the sheet (1) tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Not Intersect(Target, Range("R:R")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim Lastrow As Long
Lastrow = Sheets(2).Cells(Rows.Count, "R").End(xlUp).Row + 1
Rows(Target.Row).Copy Destination:=Sheets(2).Rows(Lastrow)
Rows(Target.Row).EntireRow.Delete
End If
End Sub

That worked perfect... Double clicking doesn't bother me, I've set a conditional formatting on the box to turn green so it gives an indication that it should be double click anyway
Thank you
 
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
That worked perfect... Double clicking doesn't bother me, I've set a conditional formatting on the box to turn green so it gives an indication that it should be double click anyway
Thank you
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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