Excel 2000 and Importing huge ASCII files

  • Thread starter Thread starter Goran Stjepanovic
  • Start date Start date
G

Goran Stjepanovic

Hello,

I would like to load a big ascii file into Excel and split it into different
worksheets within the same workbook. The criteria to split is an empty line
with the next line being 1.0 In total the files contains 147 entities.

Anybody who could help me with VBA code?

--
Goran Stjepanovic

=====================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
=====================================================
 
Goran,

Try the sub below.

HTH,
Bernie
MS Excel MVP

Sub SplitLargeFileIntoSheets()
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
Dim Added As Boolean

FileName = Application.GetOpenFilename
If FileName = "" Then End

FileNum = FreeFile()
Open FileName For Input As #FileNum
Application.ScreenUpdating = False
Workbooks.Add Template:=xlWorksheet

Counter = 1

Do While Seek(FileNum) <= LOF(FileNum)
Line Input #FileNum, ResultStr
ActiveCell.Value = ResultStr

If ActiveCell.Row <> 1 Then
If ActiveCell.Value = 1 And ActiveCell(0).Value = "" Then
ActiveCell(0).Resize(2, 1).EntireRow.Delete
ActiveWorkbook.Sheets.Add
Added = True
End If
End If

If Added Then
Added = False
Else
ActiveCell.Offset(1, 0).Select
End If

Counter = Counter + 1
Loop
Close
End Sub
 
Back
Top