Getting "Application Defined or Object Defined" error '1004"

0

1

So I was trying to copy data from different sheet and paste on current and I am getting this error:

"Application Defined or Object Defined" error '1004"

Can someone help me with this ?

Option Explicit
Sub finddata()

Dim fname As String
Dim FinalRow As Long
Dim i As Integer


Sheets("Report").Range("A10:N200").ClearContents
fname = Sheets("Report").Range("A4").Value
FinalRow = Sheets("Database").Range("A1000").End(xlUp).Row

For i = 3 To FinalRow
    If Sheets("Database").Cells(i, 1) = fname Then
    Sheets("Database").Range(Cells(i, 11), Cells(i, 24)).Copy  ----> Getting "Application Defined or Object Defined" error '1004" on this line
    Sheets("Report").Range("A1000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
End If
Next i

End Sub

AriKari

Posted 2015-08-25T09:42:48.917

Reputation: 113

Answers

2

The reference to Cells isn't on the same sheet as the call to Range. This is mentioned in the docs for Range.Item. It will will work if Database is the active sheet but not otherwise.

Try replacing the error line with

With Sheets("Database")
    .Range(.Cells(i, 11), .Cells(i, 24)).Copy 
End With

Note the periods before Cells.

cxw

Posted 2015-08-25T09:42:48.917

Reputation: 1 389

Can you troubleshoot and tell me the right solution ? – AriKari – 2015-08-25T10:01:47.767

When I ran it first time it works perfectly second time it gives an error. – AriKari – 2015-08-25T10:02:40.070

Hey it worked perfectly thank you very much Sir. – AriKari – 2015-08-25T10:04:23.930