Run-time error '1004': PasteSpecial method of Range class failed

level3ninja

New Member
Joined
Feb 21, 2011
Messages
14
Hi.

I'm using Excel 2010, Windows 7.
For the life of me I cannot understand the logic behind pasting using vba in excel. :oops:
Anyhow, I'm getting the above error on the following macro:

Code:
Sub Heading_Relining_Up()
Dim rownumber As Long
Dim rcount As Long
 
rownumber = 0
 
rcount = ThisWorkbook.Worksheets(1).UsedRange.Rows.Count
 
Do
     Range("D1").Offset(rownumber).Select
    If ActiveCell = "" Then
        rcount = rcount + 1
    Else
        If ActiveCell.Offset(0, 1) = "H" Then
            ActiveCell.Cut
            ActiveCell.Offset(0, -1).Select
            ActiveCell.PasteSpecial (PasteAsXLPasteType = xlPasteAll)
            ActiveCell.Offset(0, 2).Cut
            ActiveCell.Offset(0, 3).Select
            ActiveCell.PasteSpecial (xlPasteValues)
            rownumber = rownumber + 1
        Else
            rownumber = rownumber + 1
        End If
    End If
     
     
Loop Until rownumber = rcount
 
Range("A1").Select
 
ExitSub:
End Sub

The following line is highlighted when I Debug:
"ActiveCell.PasteSpecial (PasteAsXLPasteType = xlPasteAll)"

I have tried numerous different methods of pasting, but there must be something I'm missing that will allow all manner of paste methods to be used after it's fixed.

Thanks for your time.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
HI! have you try using ActiveCell.PasteSpecial xlPasteValues without parenthesis? your code worked for me with that...
 
Upvote 0
Hi! Thanks for replying :)
I tried it, but still get the same error.

(I also realised I made a mistake in the code, that made it loop if there was a blank cell in col D.
Here's the fixed version:

Code:
Sub Heading_Relining_Up()
Dim rownumber As Long
Dim rcount As Long
 
rownumber = 0
 
RowCount = ThisWorkbook.Worksheets(1).UsedRange.Rows.Count
 
Do
     Range("D1").Offset(rownumber).Select
    If ActiveCell = "" Then
        rownumber = rownumber + 1
    Else
        If ActiveCell.Offset(0, 1) = "H" Then
            ActiveCell.Cut
            ActiveCell.Offset(0, -1).Select
            ActiveCell.PasteSpecial xlPasteAll
            ActiveCell.Offset(0, 2).Cut
            ActiveCell.Offset(0, 3).Select
            ActiveCell.PasteSpecial xlPasteValues
            rownumber = rownumber + 1
        Else
        End If
        rownumber = rownumber + 1
    End If
     
     
Loop Until rownumber = rcount
 
Range("A1").Select
 
ExitSub:
End Sub
 
Upvote 0
For some reason I had mixed up rcount and rowcount when I had changed from one to the other.

Thought that had fixed it, but it hasn't. Still having the same issue.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,058
Messages
6,128,538
Members
449,456
Latest member
SammMcCandless

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