PasteSpecial method of Range class failed

stuartpurdie

New Member
Joined
Apr 1, 2004
Messages
8
:help:

I'm trying to set up a toolbar button to paste formulas only. I want to be able to copy a cell, select a destination and then hit the button to paste the formula.

I edited a recorded macro to leave: -

Sub mcrPasteFormulas()
'
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= False, Transpose:=False
'
End Sub

When I copy the cell, select the destination then run the macro I get a "Runtime error '1004': PasteSpecial method of Range class failed".

Can anyone tell me what's going wrong?
:banghead:
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Yes, what's going wrong is that you didn't copy anything, at least not as far as the macro is concerned. Precede your PasteSpecial line with the cell range you want to copy, such as
Range("A1").Copy

or, copy a cell and while in copy mode run the macro.

Otherwise, VBA sees nothing on the clipboard.
 
Upvote 0
It works when I do it. There's something else going on here. Maybe the code is not in the module of the button (or attached to the Forms button) you are clicking. Maybe you really are not in copy mode. Maybe the workbook is in design mode if it's a command button. Maybe there's no formula in the cell(s) being copied. Maybe there is other code in the workbook, such as a selection event, that is clearing the clipboard.

There are all sorts of possibilities; it's hard to tell from a distance. On the face of your description, everything should work as it's been presented. Take a close look at other VBA modules in your workbook, especially including the workbook and worksheet modules, to see if any conflicting or interfering code exists. Also, tell us *exactly* what kind of button or object you are clicking, and under what conditions, and exactly what you are doing up to that point of the mouse click.
 
Upvote 0
I have somewhat similar problem...

I try to insert reference in cells in the named range. The code uses Selection.FillDown and Selection.FillRight methods, but... I want the destinatioon range to have the original formatting (that is lost after applying these methods).
So I tried to copy the original formatting, then insert cell references and afterwards reapply the original formatting... but I got this error "PastSpecial Method of Range class failed".

Seems there was nothing to copy because there were other code lines between *copy and *PastSpecial?

IF so, can you please advise how can I restore the original formatting of the destination range?

Below is the code I used:

Windows("Book2.xlsx").Activate
Range("LinkDestination").Select

Selection.Copy

ActiveCell.FormulaR1C1 = "=[Book1.xlsm]Sheet1!RC"
Selection.FillDown
Selection.FillRight

Range("LinkDestination").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
 
Upvote 0
This is actually quite a different question.:)

The original is about using a custom command button on a toolbar.

Anyway, I think the problem could be that you select the named range again just before you do the paste special or it might be earlier in the code.

That, and othere problems, could be avoided by not using select in the first place.

What is it you are actually trying to copy?

That's not clear - you copy a range, don't really do anything with it, put a cell in the active cell then fill down/right.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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