Excel's favorite RT error - PasteSpecial method of Range Class failed. grrr

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
I'm trying to Move a Row of Data to ANOTHER WORKSHEET (Same WB) if Column 8 of each row included the text "closed". Once the First such row is Cut and Deleted the code is taking me to Sheet2 but bombing after running the code line IN RED (below). Current getting the 1004 error. What's missing/wrong? TIA, Jim

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Columns(8), Target) Is Nothing Then Exit Sub
Dim i As Long
Application.EnableEvents = False
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    If Cells(i, 8).Value = "closed" Then
        Cells(i, 8).EntireRow.Cut
        Cells(i, 8).EntireRow.Delete
        With Worksheets("Sheet2")
            NBR = .Range("A" & Rows.Count).End(xlUp).Row + 1
            .Range("A" & NBR).PasteSpecial Paste:=xlPasteValues
        
      
        End With
    End If
Next i
Application.EnableEvents = True
End Sub
 

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)
Try doing a cut and paste special manually. You cant. You will also struggle if you delete the row between a copy and a paste.
 
Upvote 0
Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Columns(8), Target) Is Nothing Then Exit Sub
    Dim i As Long
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 2 Step -1
        If Cells(i, 8).Value = "closed" Then
            Cells(i, 8).EntireRow.Copy
            With Worksheets("Sheet2")
                NBR = .Range("A" & Rows.Count).End(xlUp).Row + 1
                .Range("A" & NBR).PasteSpecial Paste:=xlPasteValues
            End With
            Cells(i, 8).EntireRow.Delete
        End If
    Next i
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
try this instead.

It skips using the paste altogheter.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Columns(8), Target) Is Nothing Then Exit Sub
Dim i As Long
Application.EnableEvents = False
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    If Cells(i, 8).Value = "closed" Then
         With Worksheets("Sheet2")
            NBR = .Range("A" & Rows.Count).End(xlUp).Row + 1
            .Rows(NBR).EntireRow.Value = ActiveSheet.Rows(i).EntireRow.Value
         End With
         Rows(i).EntireRow.Delete
    End If
Next i
Application.EnableEvents = True
End Sub
 
Upvote 0
On second thought, do you really need to loop through all the rows? If you are simply entering "closed" in column H and you want that row cut to Sheet2 then this would do it:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Columns(8), Target) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If Target = "closed" Then
        Target.EntireRow.Copy
        Sheets("Sheet2").Cells(Sheets("Sheet2").Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
        Target.EntireRow.Delete
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Does this event code work for you...
Code:
[table="width: 500"]
[tr]
	[td]Private Sub Worksheet_Change(ByVal Target As Range)
  If Intersect(Columns(8), Target) Is Nothing Then Exit Sub
  Dim LR As Long, R As Long
  Application.EnableEvents = False
  LR = Range("A" & Rows.Count).End(xlUp).Row
  For R = LR To 2 Step -1
    If LCase(Cells(R, "H").Value) = "closed" Then
      Rows(R).Cut Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1)
      Rows(R).Delete
    End If
  Next
  Application.EnableEvents = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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