title: Application-defined or object-defined error (1004) - Excel VBA
body: <p>I have a workbook called '<code>EvaluationLog.xlsm</code>' and I need to transfer specific cells (not the whole row) from the first worksheet to another existing workbook called '<code>IndicatorLog.xlsm</code>' located in the same directory. The target worksheet is also the first one. I'm trying to have the macro hosted in the '<code>IndicatorLog</code>' workbook.</p>
  
  <p>Specific cells in each row from the source are only to be copied if the contents in column 'O' is 'No' or if the contents of column 'J' is 'Initial'. The actual source data starts on row 8 and the target range also starts on row 8.</p>
  
  <p>I'm having two issues. The first one is that I'm getting this error 'Application-defined or object-defined error (1004)' at the first line where I'm trying to copy cells. </p>
  
  <p>This is the line: <code>TargetSheet.Range("A" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“A” &amp; i).Value</code></p>
  
  <p>The second issue is that when I already have the source workbook open, I get a warning about trying to open it again even though I have a function to try to avoid that. :(</p>
  
  <p>I assigned the macro to a form button. Any help will be greatly appreciated! :)</p>
  
  <p>Here are the two Excel files:</p>
  
  <p><a href="https://drive.google.com/folderview?id=0B73fZz19sQ7efnJmUzA1WktWb3Btbm90MnpkWkZQYy1XQm5Ua18wZUo3WXotcmx3Z1dONjg&amp;usp=sharing" rel="nofollow">Files</a></p>
  
  <p>Here's the code:</p>
  
  <pre><code>Sub MergeFromLog()
  
  Dim TargetSheet As Worksheet
  Dim NRow As Long
  Dim SourceFileName As String
  Dim WorkBk As Workbook
  Dim LastRow As Integer, i As Integer, erow As Integer
  
  ' Set destination file.
  Set TargetSheet = ActiveWorkbook.Worksheets(1)
  
  ' Set source file.
  SourceFileName = ActiveWorkbook.Path &amp; "\2015-2016 Evaluation Log.xlsm"
  
  ' NRow keeps track of where to insert new rows in the destination workbook.
  NRow = 8
  
  ' Open the source workbook in the folder
  If CheckFileIsOpen(SourceFileName) = False Then
      Set WorkBk = Workbooks.Open(SourceFileName)
  Else
      Set WorkBk = Workbooks(SourceFileName)
  End If
  
  LastRow = WorkBk.ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
  
  For i = 8 To LastRow
  
      If WorkBk.ActiveSheet.Range("O" &amp; i) = "No" Or WorkBk.ActiveSheet.Range("J" &amp; i) = "Initial" Then
  
          ' Copy Student Name
          TargetSheet.Range("A" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“A” &amp; i).Value
          ' Copy DOB
          TargetSheet.Range("B" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“C” &amp; i).Value
          ' Copy ID#
          TargetSheet.Range("C" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“D” &amp; i).Value
          ' Copy Consent Day
          TargetSheet.Range("D" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“L” &amp; i).Value
          ' Copy Report Day
          TargetSheet.Range("E" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“N” &amp; i).Value
          ' Copy FIE within District Timelines?
          TargetSheet.Range("F" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“O” &amp; i).Value
          ' Copy Qualified?
          TargetSheet.Range("H" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“A” &amp; i).Value
          ' Copy Primary Eligibility
          TargetSheet.Range("I" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“U” &amp; i).Value
          ' Copy ARD Date
          TargetSheet.Range("J" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“R” &amp; i).Value
          ' Copy ARD within District Timelines?
          TargetSheet.Range("K" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“S” &amp; i).Value
          ' Copy Ethnicity
          TargetSheet.Range("M" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“F” &amp; i).Value
          ' Copy Hisp?
          TargetSheet.Range("N" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“G” &amp; i).Value
          ' Copy Diag/LSSP
          TargetSheet.Range("O" &amp; NRow).Value = WorkBk.ActiveSheet.Range(“X” &amp; i).Value
  
          NRow = NRow + 1
  
      End If
  
  Next i
  
  End Sub
  
  Function CheckFileIsOpen(chkSumfile As String) As Boolean
  
  On Error Resume Next
  
  CheckFileIsOpen = UCase(Workbooks(chkSumfile).Name) Like UCase(chkSumfile)
  
  On Error GoTo 0
  
  End Function
  </code></pre>