Why is the Paste action not working for this range object?

musicgold

Board Regular
Joined
Jan 9, 2008
Messages
197
Hi,

In the following code, I am getting error 1004 on the last line (red). All I am trying to do is copy data from an range and paste it into another range.

Error: Run-time error '1004': Pastespecial method or range class failed.

What am I doing wrong?

Thanks

Code:
Public Sub Testing()
Dim Rng1 As Range
Dim oCell As Range
Dim holder As Range
Dim Target As Range
Dim WSaddr As String


Set Rng1 = Selection
Set holder = Range(Rng1, ActiveCell.End(xlDown))

Range(Rng1, ActiveCell.End(xlDown)).Copy


Set Target = Application.InputBox _
         (prompt:="Select Target cell", Title:="Target", Left:=-2, Top:=-10, Type:=8)

   
Target.Select
[COLOR="#FF0000"]Target.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False[/COLOR]

  

End Sub
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try it like
Code:
Public Sub Testing()
Dim Rng1 As Range
Dim oCell As Range
Dim holder As Range
Dim Trgt As Range
Dim WSaddr As String


Set Rng1 = Selection
Set holder = Range(Rng1, ActiveCell.End(xlDown))
Set Trgt = Application.InputBox _
         (prompt:="Select Target cell", Title:="Target", Left:=-2, Top:=-10, Type:=8)

Range(Rng1, ActiveCell.End(xlDown)).Copy



   
Trgt.PasteSpecial xlPasteValues

  

End Sub
I would also advise against using VBA keywords such as Target for the names of variables.
 
Upvote 0
Thanks Fluff.

However, I am confused now.

Why is the location of Range(Rng1, ActiveCell.End(xlDown)).Copy in the code making such a difference?
 
Upvote 0
I suspect that when you used the inputbox to get the paste range, it was clearing the clipboard, so there was nothing to paste.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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