Paste Links

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi, Im wanting to copy a range and paste as a link.

The Excel Macro recorder would create something like this...

Code:
Range("A1:A3").Select
    Selection.Copy
    Range("D1").Select
    ActiveSheet.Paste Link:=True

How can you paste a link without first selecting the destination cells? Pasting a link is only available with a sheet object so how do I include the destination range? There is no link argument for the copy method.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
According to the VBE Help file it cannot be done.

Have a look at Paste Method (Worksheet Object).
 
Upvote 0
Thanks Ponsy, just as I suspected then. Although correct in most instances its a bit of a fallacy that you dont have to select objects to work with them as in some cases thats not correct. Unless you know how to use an expression which includes a range and that Excel will accept?
 
Upvote 0
Chitosunday said:
But isn't it the same as our typical formula :Sub test()
Range("d1:d3").Formula = "=a1"

Yes, thank you as thats the method I should use. It just seems strange that I have to use an alternative way to achieve the result where theres a specific method of doing a paste as a link but it appears it only can be used by selecting a cell first. I just wanted to confirm that.

Im just trying to understand what code you should use when copying and pasting as I prefer to use those which dont require me to select something first.

So if Im wanting to do a straight copy to another range I use...
Range("A1:A10").Copy Range("C1:C10")

But if Im wanting to copy as a link I need to use...
Range("A1:A10").Copy
Range("C1").Select 'or Range("C1:C10").Select
ActiveSheet.Paste Link:=True

Or to link without selecting...
Range("C1:C10").FormulaR1C1 = "=RC[-2]"

EDIT:
I tried to use the destination argument with ActiveSheet.Paste but this fails with an err 1004 Worksheet object class failed.

Sub test()
Range("A1:A10").Copy
ActiveSheet.Paste Destination:=Range("C1:C10"), Link:=True
End Sub
 
Upvote 0
My two cents:
Nathan Oliver said:
Avoid Excel's Paste Special functionality with respect to VBA code like it's the plague.
Link a cell and autofill, or copy normally. MS has bolloxed up the functionality of Paste Special in VBA in terms of what could have been nice native functionality. No need to figure it out, it's crazier than fiction, look elsewhere. I take my own medicine here and look for other ways to accomplish my goal sets.
 
Upvote 0
Thank you Nate. Im not sure if you saw my edit so do you know why this bombs or is this bolloxed as well?

Code:
Sub test() 
Range("A1:A10").Copy 
ActiveSheet.Paste Destination:=Range("C1:C10"), Link:=True 
End Sub
 
Upvote 0
I don't know, and not my point. Here's my point:

The PasteSpecial Method or anything coming from the P.S. dialog is flawed with respect to Range Objects and Selecting. With respect to VBA, don't use it, I don't.
 
Upvote 0
Thanks Nate, I appreciate your comments. I'll just use FormulaR1C1 if I want to link a cell.

(y)
 
Upvote 0
parry said:
Thank you Nate. Im not sure if you saw my edit so do you know why this bombs or is this bolloxed as well?

Code:
Sub test() 
Range("A1:A10").Copy 
ActiveSheet.Paste Destination:=Range("C1:C10"), Link:=True 
End Sub

It doesn't work because MS didn't allow for such a method.

As previously posted, the Help file specifically states for the Paste Method that :
- if the Link argument is specified, the Destination argument cannot be used, and
- If the Destination argument is specified, the Link argument cannot be used, and
- If the Destination argument is not specified, the destination range must be selected before the Paste Method is used.

It does seem odd that it has to be done like this, but at least the Help file explains it.
 
Upvote 0

Forum statistics

Threads
1,203,111
Messages
6,053,569
Members
444,673
Latest member
Jagadeshrao

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