title: How to do searching after a particular line in Text file from Excel
body: <p>I have a text file like below</p>
  
  <pre><code>Job Number - 1234  
  Job Name - Vaxation  
  Start Time - 29-Apr-2013 10:30   
  Finish Time - 29-Mar-2013 4:00 PM  
  Job Number - 2349  
  Job Name - Immunity  
  Start Time - 29-Apr-2013 11:30  
  Finish Time - 29-Mar-2013 2:00 PM  
  </code></pre>
  
  <p>The same will be repeated with different data.  </p>
  
  <p>I am doing the search with Job Number, if it is found then get the start time and Finish time into excel sheet.  </p>
  
  <p>I tried the Code below</p>
  
  <pre><code>Public Function ReadTxtFile()
      Dim TxtLine As String
      Dim CntRow As Integer
      Dim CntRow1 As Integer
      Dim CntRow2 As Integer
  
      FNum = FreeFile()
  
      Open TxtFile For Input As #FNum
  
      CntRow1 = 0
  
      While Not EOF(FNum)
          Line Input #FNum, TxtLine
          If InStr(1, TxtLine, "1234", vbTextCompare) = 0 Then
              CntRow1 = CntRow1 + 1
          Else
              CntRow2 = CntRow1 + 1
          End If
      Wend
  
      Call Getdat
  End Function
  
  Function Getdat()
      Seek FNum, CntRow2
  
      While Not EOF(FNum)
          Line Input #FNum, TxtLine
  
          If InStr(1, TxtLine, "StartTime", vbTextCompare) &lt;&gt; 0 Then
              GLRow = ws_sh.Range("B:B").Cells.Find(Format(Now() - 1, DatFormat1), searchorder:=xlByRows, searchdirection:=xlPrevious).Row
              ws_sh.Range(Col1 &amp; GLRow) = Format(Now() - 1, DatFormat1)
              ws_sh.Range(Col2 &amp; GLRow) = Mid(TxtLine, 33, 5)
              Exit Function
          End If
      Wend
  End Function
  </code></pre>