#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Copy Method

I was just wondering why this line of code works:

mySht.Range("A5:A" & endRow).Copy

while this one produces runtime error 1004

mySht.Range(Cells(5, 1), Cells(endRow, 1)).Copy

Regards
Rowan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Copy Method

Try this... You need to be a little more explicit with your references...

mySht.Range(mySht.Cells(5, 1), mySht.Cells(endRow, 1)).Copy

As a guess it can not resolve Cells...

HTH

"Rowan" wrote:

I was just wondering why this line of code works:

mySht.Range("A5:A" & endRow).Copy

while this one produces runtime error 1004

mySht.Range(Cells(5, 1), Cells(endRow, 1)).Copy

Regards
Rowan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Copy Method

Probably because mysht is not the active sheet and the Cells property points
to the active sheet. Try

mySht.Range(mySht.Cells(5, 1), mySht.Cells(endRow, 1)).Copy


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Rowan" wrote in message
...
I was just wondering why this line of code works:

mySht.Range("A5:A" & endRow).Copy

while this one produces runtime error 1004

mySht.Range(Cells(5, 1), Cells(endRow, 1)).Copy

Regards
Rowan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Copy Method

Thanks Jim, Bob

I was missing the fact that Cells refers to the activesheet only unless
referenced otherwise.

Regards
Rowan

"Rowan" wrote:

I was just wondering why this line of code works:

mySht.Range("A5:A" & endRow).Copy

while this one produces runtime error 1004

mySht.Range(Cells(5, 1), Cells(endRow, 1)).Copy

Regards
Rowan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Copy Method

Rowan,

Just for interest, to avoid repetition of the mySht object, make it more
efficient, and more readable, I would code it as

With mySht
.Range(.Cells(5, 1), .Cells(endRow, 1)).Copy
'... rest of code
End With

Note the dots before Range and Cells.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Rowan" wrote in message
...
Thanks Jim, Bob

I was missing the fact that Cells refers to the activesheet only unless
referenced otherwise.

Regards
Rowan

"Rowan" wrote:

I was just wondering why this line of code works:

mySht.Range("A5:A" & endRow).Copy

while this one produces runtime error 1004

mySht.Range(Cells(5, 1), Cells(endRow, 1)).Copy

Regards
Rowan



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method 'Copy' of object'_Worksheet failed q2w3e4r Excel Worksheet Functions 1 February 7th 07 01:17 PM
worksheet copy method Marek Excel Programming 1 September 6th 04 04:40 PM
Looking for faster method for Copy & Paste David Copp[_4_] Excel Programming 5 August 25th 04 04:32 AM
Copy Method of Worksheet Class Failed Steph[_3_] Excel Programming 0 April 5th 04 11:12 PM
Copy method fails in IIS Domien Excel Programming 0 February 19th 04 02:46 PM


All times are GMT +1. The time now is 02:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"