Automatically move rows to another sheet

supernam

New Member
Joined
Jul 15, 2019
Messages
7
Hello to you all! I hope you all are doing well during this pandemic.
Before I begin please understand I am not an excel wiz by any means, and messing with VBA is a very weak point for me. With that said, I would like to get some help with moving rows when the completed column shows "Y" to the closed discrepancies tab.Here is what I have thus far.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Application.EnableEvents = False
'If Cell that is edited is in column M and the value is completed then
If Target.Column = 12 And Target.Value = "yes" Then
'Define last row on completed worksheet to know where to place the row of data
LrowCompleted = Sheets("Closed Discrepancies").Cells(Rows.Count, "A").End(xlUp).Row
'Copy and paste data
Range("A" & Target.Row & ":M" & Target.Row).CopySheets("Closed Discrepancies").Range("A" & LrowCompleted + 1).PasteSpecial Paste:=xlPasteValues
'Delete Row from Open Discrepancies
Range("A" & Target.Row & ":M" & Target.Row).Delete xlShiftUp
End If
Application.EnableEvents = True
End Sub


Thank you in advance for your help! I am truly appreciative for those of you that take the time to assist.


Excel help Pic.PNG
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
In one place you indicate that the entry in column 12 will be a "Y" and in your sample code you use "yes". The code below has a line for each but both are commentd out with asn apostrophe. Choose the corredt one and remove the apostrophe, delete the other line and then paste the code into the sheet code module.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("L:L")) Is Nothing Then
    'If LCase(Target.Value) = "yes" Then 'remove the apostrophe for the correct code
    'If UCase(Target.Value) = "Y" Then   'remove the apostrophe for the correct code
        Range("A" & Target.Row).Resize(, 13).Copy
        Sheets("Closed Discrepancies").Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValues
        Range("A" & Target.Row).Resize(, 13).Delete xlShiftUp
    End If
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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