title: Macro that imports 100 .txt files into multiple sheets in excel in true chronological order
body: <p>Hoping I can get some advice regarding my VBA code, I have a 100 text files numbered <strong>1_OUT_IX_-500.TXT, 2_OUT_IX_-490.TXT</strong> and so on till 101_OUT_IX_500.TXT, so far I haven't had any luck with regards to finding a macro that imports the .TXT files into an excel work book in a chronological order i.e. <strong>1_OUT_IX_-500.TXT, 2_OUT_IX_-490.TXT</strong> and so on instead of <strong>1_OUT_IX_-500.TXT, 10_OUT_IX_-410.TXT</strong> and change the name of the work sheet to that of the imported files.</p>
  
  <p>I've got a macro below and it seems to do most of it <strong><em>but</em></strong> I've noticed that some of the imported data is inaccurate and more importantly they are not in a true chronological order, this is important as I create a summary sheet from the values in AO2:AQ2 in a new worksheet.</p>
  
  <p>so basically any help with either modifying my macro or suggests of a new macro are welcome. honestly any help is truly appreciated, and thank you in advance for taking the time to read this, again any help is truly appreciated.</p>
  
  <p>Thank you </p>
  
  <pre><code>    Sub MacroLoop()
  '
  '
  Application.ScreenUpdating = False
  Dim strFile As String
  Dim ws As Worksheet
  Dim i As Integer
  For i = 1 To 101
  strFile = Dir("C:\Users\Abubakar Adan\JSIM\Ig=520\Ic=340\340_TXT\" &amp; i &amp; "_*.TXT")
  If strFile &lt;&gt; "" Then
  Set ws = Sheets.Add
  With ws.QueryTables.Add(Connection:= _
      "TEXT;" &amp; "C:\Users\Abubakar Adan\JSIM\Ig=520\Ic=340\340_TXT\" &amp; strFile, Destination:=Range("$A$2"))
          .Name = strFile
          .FieldNames = True
          .RowNumbers = False
          .FillAdjacentFormulas = False
          .PreserveFormatting = True
          .RefreshOnFileOpen = False
          .RefreshStyle = xlInsertDeleteCells
          .SavePassword = False
          .SaveData = True
          .AdjustColumnWidth = True
          .RefreshPeriod = 0
          .TextFilePromptOnRefresh = False
          .TextFilePlatform = 1251
          .TextFileStartRow = 1
          .TextFileParseType = xlDelimited
          .TextFileTextQualifier = xlTextQualifierDoubleQuote
          .TextFileConsecutiveDelimiter = True
          .TextFileTabDelimiter = True
          .TextFileSemicolonDelimiter = False
          .TextFileCommaDelimiter = False
          .TextFileSpaceDelimiter = True
          .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
          .TextFileTrailingMinusNumbers = True
          .Refresh BackgroundQuery:=False
  End With
  ws.Name = strFile
  End If
  Next i
  End Sub
  </code></pre>