title: Excel VBA: Import data from all text files in a directory onto a new row in excel?
body: <p>I am using VBA to import all the data from a single text file onto a new row in excel and then once the data from the text file is imported move the text file to another location/directory. I have done this much.</p>
  
  <p>However now I have multiple text files in a directory and want to get the data from each text file and insert it onto a new row so I end up getting the following results:</p>
  
  <pre><code>Text File 1
  A
  B
  C
  D
  
  
  Text File 2
  T
  L
  V
  P
  
  
  Excel:
  Column A     Column B       Column C         Column D        
  A            B              C                D   
  T            L              V                P
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>Sub ImportFile()
  
      Dim rowCount As Long
  
      rowCount = ActiveSheet.UsedRange.Rows.Count + 1
  
      If Cells(1, 1).Value = "" Then rowCount = 1
  
  
      Close #1
      Open "Z:\Incident Logs\Unactioned\IN94LQ3Z.txt" For Input As #1
      A = 1
       Do While Not EOF(1)
              Line Input #1, TextLine
              Cells(rowCount, A) = TextLine
              A = A + 1
          Loop
      Close #1
  
  
   Dim d As String, ext, x
  Dim srcPath As String, destPath As String, srcFile As String
  srcPath = "Z:\Incident Logs\Unactioned\"
  destPath = "Z:\Incident Logs\Actioned\"
  ext = Array("*.txt", "*.xls")
  For Each x In ext
      d = Dir(srcPath &amp; x)
          Do While d &lt;&gt; ""
              srcFile = srcPath &amp; d
              FileCopy srcFile, destPath &amp; d
              Kill srcFile
              d = Dir
          Loop
  Next
  
  
  End Sub
  </code></pre>
  
  <p>Please can someone show me a way of doing what i need? Thanks in advance</p>