Drop that in a module - then run it and see if it works... (In excel!)Code:Option Explicit Public Sub ImportDataFile() Dim sht As Worksheet Dim strChar As String Dim strColumnData As String Dim lngColumn As Long, lngRow As Long Set sht = ActiveSheet '---- close the channel - incase its still open Close #1 Open "C:\DataFile.csv" For Input As #1 lngColumn = 1 lngRow = 1 strChar = String(1, " ") '---- keep looping until the file runs out Do Until EOF(1) strChar = Input(1, #1) '---- if its the separator If Asc(strChar) = 9 Then '---- output the data and '---- move the column sht.Cells(lngRow, lngColumn) = strColumnData lngColumn = lngColumn + 1 strColumnData = "" '---- if the column is > 4 then reset the column and add one to the row If lngColumn > 4 Then lngColumn = 1 lngRow = lngRow + 1 End If Else '---- add the char to the data '---- * you could add extra checks here to remove speechmarks etc strColumnData = strColumnData & strChar End If Loop sht.Cells(lngRow, lngColumn) = strColumnData '---- dump the last of the data in the cell '---- close the channel Close #1 Set sht = Nothing End Sub
If it does, see if you understand how I did it.
might not be fast on huge files tho...




Reply With Quote