title: import text file data into excel workbook VBA
body: <p>I  have an excel workbook where the user imports text file information for calculations and plots to be generated. My code works great but I have ran into a bit of an issue. For most text files I need to start copying the information from row 2 but there is a few text files where I need to start copying information from a different row (see the two images below). So essentially I need to start copying information one row below the row that says "Depth". <a href="https://i.stack.imgur.com/102A8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/102A8.jpg" alt="This image has depth in the first row"></a></p>
  
  <p>^This image has depth in the very first row of the text file.
  <a href="https://i.stack.imgur.com/1fHTi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fHTi.jpg" alt="enter image description here"></a>
  ^Whereas this image has depth further down in the text file. </p>
  
  <p>Here is the code I currently have for importing the text files:</p>
  
  <pre><code>Sub Import_Textfiles()
  Dim fName As String, LastCol As Integer
  
  With Application
      .ScreenUpdating = False
      .Calculation = xlCalculationManual
  End With
  
  Worksheets("Data Importation Sheet").Activate
  
  LastCol = Cells(2, Columns.count).End(xlToLeft).Column
  If LastCol &gt; 1 Then
  LastCol = LastCol + 1
  End If
  
  fName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
  
  If fName = "False" Then Exit Sub
  
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" &amp; fName, _
          Destination:=Cells(2, LastCol))
          .Name = "2001-02-27 14-48-00"
          .FieldNames = True
          .RowNumbers = False
          .FillAdjacentFormulas = False
          .PreserveFormatting = True
          .RefreshOnFileOpen = False
          .RefreshStyle = xlInsertDeleteCells
          .SavePassword = False
          .SaveData = True
          .AdjustColumnWidth = False
          .RefreshPeriod = 0
          .TextFilePromptOnRefresh = False
          .TextFilePlatform = 437
          .TextFileStartRow = 2
          .TextFileParseType = xlFixedWidth
          .TextFileTextQualifier = xlTextQualifierDoubleQuote
          .TextFileConsecutiveDelimiter = False
          .TextFileTabDelimiter = True
          .TextFileSemicolonDelimiter = False
          .TextFileCommaDelimiter = False
          .TextFileSpaceDelimiter = False
          .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
          .TextFileFixedColumnWidths = Array(14, 14, 8, 16, 12, 14)
          .TextFileTrailingMinusNumbers = True
          .Refresh BackgroundQuery:=False
      End With
  
     Call Macro
     'counts the number of times this macro runs aka identifier
  
      Dim strShortName As String
      Dim string1 As String
      Dim reference As Range
      Dim emptycell As Integer
      Dim LastRow As Integer
      Dim LastRow2 As Integer
      Dim LastRow3 As Integer
  
      i = Worksheets("Hidden").Range("B2").Value
  
      string1 = Worksheets("Hidden").Cells(i + 1, 1)
  
      Worksheets("Data Importation Sheet").Activate
  
      Cells(1, LastCol) = "Depth"
      Cells(1, LastCol + 1) = "A0_ " &amp; string1
      Cells(1, LastCol + 2) = "A180_ " &amp; string1
      Cells(1, LastCol + 3) = "A_Sum_ " &amp; string1
      Cells(1, LastCol + 4) = "B0_ " &amp; string1
      Cells(1, LastCol + 5) = "B180_ " &amp; string1
      Cells(1, LastCol + 6) = "B_Sum_ " &amp; string1
  
  
      'New Adding Reading Date to Excel Sheet:
      Dim fileDate1 As String
      Dim fileDate2 As String
      Dim A As String
  
      fileDate1 = Mid(fName, InStrRev(fName, "\") + 1)
      fileDate2 = Left(fileDate1, 19)
  
      LastRow = Cells(Rows.count, LastCol).End(xlUp).Row + 1
      LastRow2 = Cells(Rows.count, LastCol).End(xlUp).Row
      A = Cells(LastRow2, LastCol).Value
  
      Cells(LastRow + 1, LastCol) = "Reading Date:"
      Cells(LastRow + 2, LastCol) = fileDate2
      Cells(LastRow + 3, LastCol) = "Updating Location:"
      Cells(LastRow + 4, LastCol) = fName
      Cells(LastRow + 5, LastCol) = "Depth:"
      Cells(LastRow + 6, LastCol) = A
      Cells(LastRow + 7, LastCol) = "Identifier:"
      Cells(LastRow + 8, LastCol) = string1
  
      Sheets("Hidden").Activate
      LastRow3 = Cells(Rows.count, 3).End(xlUp).Row
      Cells(LastRow3 + 1, 3) = fileDate2
  
      Call SortDates
      'organizes imported text file dates and identifiers
  
  End Sub
  </code></pre>
  
  <p>Can anyone help me get my code to work for either case of text file data layout? TIA.</p>