ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Why am I getting R/T 1004 - Copy method of Rng class failed? (https://www.excelbanter.com/excel-discussion-misc-queries/184513-why-am-i-getting-r-t-1004-copy-method-rng-class-failed.html)

Jim May

Why am I getting R/T 1004 - Copy method of Rng class failed?
 
Sub tester()
For Each cell In Sheets("Data").Range("A2:A10")
If cell.Value = "Stuff" Then
Cells(cell.Row, 7).Copy _
Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) + 1
End If
Next cell
End Sub

Dave Peterson

Why am I getting R/T 1004 - Copy method of Rng class failed?
 
Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) + 1

will try to add 1 to whatever is in that last used cell.

If you were using a LastRow kind of thing, you could use:
LastRow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).row + 1

But I bet you just want to drop down a row.

Cells(cell.Row, 7).Copy _
Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).offset(1,0)

Jim May wrote:

Sub tester()
For Each cell In Sheets("Data").Range("A2:A10")
If cell.Value = "Stuff" Then
Cells(cell.Row, 7).Copy _
Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) + 1
End If
Next cell
End Sub


--

Dave Peterson

Jim May

Why am I getting R/T 1004 - Copy method of Rng class failed?
 
Thanks Dave;
You assumed correctly.
Jim

"Dave Peterson" wrote:

Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) + 1

will try to add 1 to whatever is in that last used cell.

If you were using a LastRow kind of thing, you could use:
LastRow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).row + 1

But I bet you just want to drop down a row.

Cells(cell.Row, 7).Copy _
Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).offset(1,0)

Jim May wrote:

Sub tester()
For Each cell In Sheets("Data").Range("A2:A10")
If cell.Value = "Stuff" Then
Cells(cell.Row, 7).Copy _
Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) + 1
End If
Next cell
End Sub


--

Dave Peterson



All times are GMT +1. The time now is 08:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com