Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Copying A Range of Cells From one Sheet to Another - Error Application Defined or Object Defined

Trying to copy the contents of Sheet 2 starting at cell A2 to Cell B2
on Sheet 1
Here's what I have:

Worksheets("Sheet 2").Range("A2", _
Cells(Worksheets("Sheet 2").UsedRange.Rows.Count, _
Worksheets("Sheet 2").UsedRange.Columns.Count)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")

This results in Error '1004' Application Defined or Object Defined.
Anythoughts on how to fix this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Copying A Range of Cells From one Sheet to Another - Error Applica

Assuming your worksheet names actually have spaces in them like your code
does(ie "Sheet 1", "Sheet 2"), then I think the problem is likely that Cells
is not qualified

Cells(Worksheets("Sheet 2").UsedRange.Rows.Count
s/b Worksheets("Sheet").Cells(Worksheets("Sheet 2").UsedRange.Rows.Count

but could be simplied by using With

With Worksheets("Sheet 2")
.Range("A2", .Cells(.UsedRange.Rows.Count, _
.UsedRange.Columns.Count)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")
End With

Using Cells(UsedRange.Rows.Count, UsedRange.Columns.Count) could be
problematic. Consider, for example, if you have data only in cells C2:C6 of
sheet 2 the range that is copied becomes A2:A5 (5 rows and 1 column in the
usedrange), not A2:C6. If you know the first row and column on Sheet 2 will
have data, it shouldn't be an issue, but if you want A2 through the last cell
of the worksheet consider (beware of the ng word wrap):

With Worksheets("Sheet 2")
.Range("A2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")
End With




"Matt" wrote:

Trying to copy the contents of Sheet 2 starting at cell A2 to Cell B2
on Sheet 1
Here's what I have:

Worksheets("Sheet 2").Range("A2", _
Cells(Worksheets("Sheet 2").UsedRange.Rows.Count, _
Worksheets("Sheet 2").UsedRange.Columns.Count)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")

This results in Error '1004' Application Defined or Object Defined.
Anythoughts on how to fix this?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Copying A Range of Cells From one Sheet to Another - Error Applica

yeah it was the Cells, good call (Can't believe i missed it, had been
trying to debug it for awhile)

thanks again

  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Copying A Range of Cells From one Sheet to Another - Error App

Correction:

Cells(Worksheets("Sheet 2").UsedRange.Rows.Count, Worksheets("Sheet
2").UsedRange.Columns.Count)
s/b
Worksheets("Sheet 2").Cells(Worksheets("Sheet 2").UsedRange.Rows.Count,
Worksheets("Sheet 2").UsedRange.Columns.Count)

Be sure to double check your worksheet names as well.


"JMB" wrote:

Assuming your worksheet names actually have spaces in them like your code
does(ie "Sheet 1", "Sheet 2"), then I think the problem is likely that Cells
is not qualified

Cells(Worksheets("Sheet 2").UsedRange.Rows.Count
s/b Worksheets("Sheet").Cells(Worksheets("Sheet 2").UsedRange.Rows.Count

but could be simplied by using With

With Worksheets("Sheet 2")
.Range("A2", .Cells(.UsedRange.Rows.Count, _
.UsedRange.Columns.Count)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")
End With

Using Cells(UsedRange.Rows.Count, UsedRange.Columns.Count) could be
problematic. Consider, for example, if you have data only in cells C2:C6 of
sheet 2 the range that is copied becomes A2:A5 (5 rows and 1 column in the
usedrange), not A2:C6. If you know the first row and column on Sheet 2 will
have data, it shouldn't be an issue, but if you want A2 through the last cell
of the worksheet consider (beware of the ng word wrap):

With Worksheets("Sheet 2")
.Range("A2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")
End With




"Matt" wrote:

Trying to copy the contents of Sheet 2 starting at cell A2 to Cell B2
on Sheet 1
Here's what I have:

Worksheets("Sheet 2").Range("A2", _
Cells(Worksheets("Sheet 2").UsedRange.Rows.Count, _
Worksheets("Sheet 2").UsedRange.Columns.Count)).Copy _
Destination:=Worksheets("Sheet 1").Range("B2")

This results in Error '1004' Application Defined or Object Defined.
Anythoughts on how to fix this?


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
Run-time error '50290': Application-defined or object-defined erro Macro button Excel Discussion (Misc queries) 1 March 12th 09 10:59 AM
Runtime error 1004- application defined or object defined erro Novice Excel Programming 0 February 6th 06 09:34 PM
Runtime error 1004- application defined or object defined erro Novice Excel Programming 1 February 6th 06 09:33 PM
Runtime error 1004- application defined or object defined erro Jim Thomlinson[_5_] Excel Programming 0 February 6th 06 09:29 PM
Range - Application Defined or Object Defined Error Dyl Excel Programming 6 October 31st 05 07:57 PM


All times are GMT +1. The time now is 10:36 PM.

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

About Us

"It's about Microsoft Excel"