Vivek
Vivek

Reputation: 15

Error copying range using Excel VBA

I'm having trouble copying a range when using a variable to refer to the range being copied. The error i get is:

Run-time error '1004': Application-defined or object-defined error

Sub temp()
Dim Data As Range
Set Data = Range("A1:C1")
Range(Data).Copy Range("E1")
End Sub

There is no problem if i use

Range("A1:C1").Copy Range("E1")

I also tried

Range(Data).Copy Destination:=Range("E1")

I'm using Excel 2010. The above sample is part of a larger body of code. I've isolated the part which generates the error.

Thanks!

Upvotes: 0

Views: 70

Answers (1)

matzone
matzone

Reputation: 5719

Since Data = Range("A1:C1")

Data.Copy Range("E1")

should work ..

Upvotes: 1

Related Questions