Copy from one sheet, paste in another, delete old row.

supernam

New Member
Joined
Jul 15, 2019
Messages
7
I could really use some help. Hopefully someone can dumb this down enough for me to understand.

When making the entry that would execute the data transfer I get the following error, Pastespecial method of range failed, and its in reference to
Sheets("Closed Discrepancies").Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValuesAndNumberFormat

If I change it to the xlPastevalues I get the following error, Delete method of range class failed for the following line
Range("A" & Target.Row).Resize(, 13).Delete Shift:=xlUp




Complete code is below.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("M:M")) Is Nothing Then
If UCase(Target.Value) = "Y" Then
Range("A" & Target.Row).Resize(, 13).Copy
Sheets("Closed Discrepancies").Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValuesAndNumberFormat
Range("A" & Target.Row).Resize(, 13).Delete Shift:=xlUp
End If
End If
Application.EnableEvents = True
End Sub


Any and all help would be greatly appreciated.

Thank you so much for taking the time to look into what I have going on!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
It should be
Rich (BB code):
xlPasteValuesAndNumberFormats
note the s at the end.
 
Upvote 0
Thank you, I corrected that and still get an error.


Delete method of range class failed for the following line
Range("A" & Target.Row).Resize(, 13).Delete Shift:=xlUp




Complete code is below.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("M:M")) Is Nothing Then
If UCase(Target.Value) = "Y" Then
Range("A" & Target.Row).Resize(, 13).Copy
Sheets("Closed Discrepancies").Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValuesAndNumberFormats
Range("A" & Target.Row).Resize(, 13).Delete Shift:=xlUp
End If
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
Is that sheet protected?
 
Upvote 0
After further review, I did have a sheet protected and then I was able to determine that the table on the sheet was preventing me from running the code. When the code runs though, it overwrites the data that is present. It does not continue adding rows. It simply puts it where it had previously depoisted the previous data. How to I get it to add another row vice dropping it on existing data?
 
Upvote 0
Does column A on the "Closed Discrepancies" sheet always have data?
 
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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