title: Extracting a row from a CSV file quickly in Excel VBA
body: <p>I have about 5000 .csv files and I want to search for one row in each file and extract it. I have pasted the key part of code below, which works, but as I have to open and close each .csv file, the process is slow for 5000 files. Is there any way to read a csv file without opening it? I had considered writing a small script to convert each csv file to Excel first? Thx.</p>
  
  <pre><code>SP_File_Name = Dir(DN_Path &amp; "*.*")
  Count = 1
  
  Set START_CELL_RANGE = TARGET_SP_SHEET.Range("B3")
  Set TICKER_CODE_RANGE = TARGET_SP_SHEET.Range("B1")
  
  
     While (SP_File_Name &lt;&gt; "")
      SP_Full_Path = DN_Path &amp; SP_File_Name
      Workbooks.OpenText Filename:=SP_Full_Path, DataType:=xlDelimited, comma:=True, Local:=True
  
      Set INPUT_WORKBOOK = ActiveWorkbook
      Set INPUT_SHEET = INPUT_WORKBOOK.Worksheets(1)
      INPUT_SHEET.Range("$A$1").Select
      Set INPUT_RANGE = ActiveCell.CurrentRegion
  
      Set INPUT_FIRST_MATCH_RANGE = INPUT_RANGE.Find(TICKER_CODE_RANGE)
  
      If INPUT_FIRST_MATCH_RANGE Is Nothing Then
      GoTo NOT_FOUND
      End If
  
  
      START_CELL = START_CELL_RANGE.Address
  
      TARGET_SP_SHEET.Range(START_CELL_RANGE.Address, START_CELL_RANGE.Offset(0, 6).Address).Value = INPUT_SHEET.Range(INPUT_FIRST_MATCH_RANGE.Address, INPUT_FIRST_MATCH_RANGE.Offset(0, 7).Address).Value
  
      ' write diagnostics
      Sheet5.Range("K" &amp; Count + 4).Value = START_CELL
      Sheet5.Range("L" &amp; Count + 4).Value = "$A$1"
      Sheet5.Range("M" &amp; Count + 4).Value = INPUT_FIRST_MATCH_RANGE.Address
      Sheet5.Range("N" &amp; Count + 4).Value = INPUT_FIRST_MATCH_RANGE.Offset(0, 7).Address
  
  NOT_FOUND:
      Set START_CELL_RANGE = START_CELL_RANGE.Offset(1, 0)
  
      Workbooks(SP_File_Name).Close SaveChanges:=False
      SP_File_Name = Dir
      Count = Count + 1
  
    Wend
  </code></pre>