View Single Post
 
Old 01-30-2013, 03:21 PM
omahadivision omahadivision is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Oct 2012
Posts: 28
omahadivision is on a distinguished road
Default How to import a text file but skip the first line regardless of characters?

Hello,

So I have a VBA code that imports a two-column text file into an Excel table. This would be very easy except that the top line isn't part of the data. It can be in any format, including letters, and numbers, and it can contain punctuation and have an odd or even number of things. I've wracked my brain trying to figure out how to skip it, or even better yet import it to a different spot on my spreadsheet. Here is my code:

Code:
On Error Resume Next
  Dim A    As Double, B  As Integer
  Dim iRow    As Long
  Dim Fname   As Variant
  Fname = f.SelectedItems(i)' This is the filename of the textfile, found from previous coding
  If Fname = False Then Exit Sub
  Open Fname For Input As #1
  iRow = 0
  Do While Not EOF(1)
     Input #1, A, B
       Cells(iRow, 2) = B ' This line puts the imported values into the excel sheet
     iRow = iRow + 1
       Loop
  Close 1
It may be handy to show what the data I am importing looks like:

Code:
Anything! 100 can, go on this1line
10.0     99
10.01    111
10.02    114
10.03    113
10.04    127
10.05    122
10.06    136
10.07    131
10.08    123
10.09    111
The first column is always the same and always starts with 10.0 followed by four spaces, which is why I don't even bother importing it. Any ideas?
Reply With Quote