title: Convert txt file to excel in vbscript
body: <p>I am trying to convert a text file into an excel sheet. This is what the format looks like. </p>
  
  <p><a href="https://i.stack.imgur.com/uz4LI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uz4LI.png" alt="Data"></a></p>
  
  <p>I have tried writing a script but currently all it does is overwrites my current text file adding my column headers. It does not add any of the data from my text file. Could anyone help me understand what I am doing wrong. </p>
  
  <pre><code>Set objExcel = CreateObject("Excel.Application")
  
  objExcel.Visible = True
  
  strInput=InputBox("Enter name of File in     C:\Users\spencerr\Desktop\MyProject\bin\")
  
  'ask user for file name
  Set wb = objExcel.Workbooks.Open("C:\Users\bob\Desktop\MyProject\bin\" &amp; strInput)
  
  'Delete labels in log
  For i = 1 To 5
      Set objRange = objExcel.Cells(1, i).EntireColumn
      objRange.Delete
  Next
  
  Set activeCell = objExcel.Cells(1, 2)
  
  Dim intVal
  Dim comVal
  Dim primeRow
  Dim largestRow
  Dim largestDec 
  Dim row
  
  primeRow = 0
  
  'filter out one measurement per second
  Do Until IsEmpty(activeCell)
      primeRow = primeRow + 1
  
      'get base integer of first value by chopping off decimal
      intVal = Fix(activeCell.Value)
      comVal = intVal
      'get all consecutive rows that have same base integer
      Do While intVal = comVal
          row = activeCell.Row
          Set activeCell = objExcel.Cells((row + 1), 2)
          comVal = Fix(activeCell.Value)
      Loop 
  
      'highest row number that contains the base integer
      largestRow = row 
  
      'delete all the rows up to the largest row
      j = primeRow    
      Do While j &lt; largestRow
          Set deleteRow = objExcel.Cells(primeRow, 2).EntireRow
          deleteRow.Delete
          j = j + 1
      Loop
  
      'compare the value right below the exact second and the value right above to see
      'which is closer to the exact second
      Set activeCell = objExcel.Cells(primeRow, 2)
      largestDec = activeCell.Value
      Set activeCell = objExcel.Cells((primeRow + 1), 2)
      comVal = activeCell.Value
  
      if (((intVal + 1) - largestDec) &gt; (comVal - (intVal + 1))) Then
      objExcel.Cells(primeRow, 2).EntireRow.Delete
      End If
  
  Loop
  
  'round all the seconds that are left to the nearesr second
  Set activeCell = objExcel.Cells(1, 2)
  Do Until IsEmpty(ActiveCell)
      row = activeCell.row
      objExcel.Cells(row, 2) = Round(activeCell.Value)
  Set activeCell = objExcel.Cells(row + 1, 2)
  Loop
  
  'add labels for KML conversion
  objExcel.Cells(1,1).EntireRow.Insert 
  objExcel.Cells(1, 2).Value = "Description"
  objExcel.Cells(1, 3).Value = "Latitude"
  objExcel.Cells(1, 4). Value = "Longitude" 
  
  wb.Save
  wb.Close
  objExcel.Quit
  </code></pre>