title: "Out of memory" stops the row counter
body: <ul>
  <li>Column "A": list of the tex file names</li>
  <li>Column "B": how many rows should be in the text files</li>
  <li>Column "C": how many rows are there in the text files factually</li>
  <li>E1: source path</li>
  <li>E2: limiter, the text file rows will be counted, if the RowInSummary number of the text file is equal or lower than E2 </li>
  </ul>
  
  <p>My script counts the rows of every files. But if I set the limiter too high (like 500.000 or 1M) or just there are too many files, the script does not count the rows of every files because the program run out of memory. (The limiter is not necessary, I have put it the "run out of memory" issue, originally I don't want to use it.)</p>
  
  <p><a href="https://i.stack.imgur.com/L50u6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L50u6.png" alt="enter image description here"></a></p>
  
  <pre><code>Sub counter()
      Dim fso As New FileSystemObject
      Dim ts As TextStream
      Dim longtext As String
      Dim lines As Variant
      Dim GoToNum As Integer
      Dim Start As Integer
      GoToNum = 2
      Start = 3
  
      Do Until IsEmpty(Cells(Start, 1))
          GoToNum = GoToNum + 1
          Start = Start + 1
      Loop
  
      For i = 3 To GoToNum
  
          If Cells(i, 2).Value &lt;= Cells(2, 5).Value Then
  
              ConOrg = Cells(1, 4).Value &amp; "\" &amp; Cells(i, 1).Value
  
              Set ts = fso.OpenTextFile(ConOrg, ForReading, False)
              longtext = ts.ReadAll
  
              ts.Close
              lines = Split(longtext, vbLf)
              Cells(i, 3) = UBound(lines) - LBound(lines) - 1
  
          End If
  
      Next i
  
  End Sub
  </code></pre>
  
  <p>How can the script count rows of every files with out "run out of memory"?</p>