Sub Split()
Dim objDestWkBk As Workbook
Dim objDestWkSht As Worksheet
Dim varResult As Variant
Dim varStartTime As Variant
Dim varEndTime As Variant
Dim dblCounter As Double
Dim lngFNumber As Long
Dim lngCounter As Long
Dim i As Long
Dim strResult As String
Dim strFName As String
Dim strDelimiter As String
On Error GoTo CleanUp
Application.ScreenUpdating = False
'Initialize variables
strFName = CStr(Application.GetOpenFilename)
If strFName = "" Or strFName = "False" Then End
lngFNumber = FreeFile()
dblCounter = 1
lngCounter = 1
'Open File
Open strFName For Input As #lngFNumber
varStartTime = Time
'Create new workbook
Set objDestWkBk = Workbooks.Add(Template:=xlWorksheet)
Set objDestWkSht = objDestWkBk.Worksheets(1)
'Import the File
Do While Seek(lngFNumber) <= LOF(lngFNumber)
Do While Not EOF(1)
Application.StatusBar = "Importing Row " & _
Format(dblCounter, "#,###") & ": " & _
Format(Seek(lngFNumber), "#,###") & " / " & _
Format(LOF(lngFNumber), "#,###") & " bytes"
Line Input #lngFNumber, strResult
Dim TextLine As String
'Check if new sheet is required
If Left(strResult, 2) = "%%" Then
'Reset lngCounter for new sheet
lngCounter = 1
With objDestWkBk
Set objDestWkSht = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
End With
Else
If Left(strResult, 1) = "=" Then _
strResult = "'" & strResult
varResult = Split(strResult, strDelimiter, -1, vbTextCompare)
For i = LBound(varResult) To UBound(varResult)
objDestWkSht.Cells(lngCounter, i + 1).Value = varResult(i)
Next i
'Increment lngcounter
lngCounter = lngCounter + 1
End If
'Increment dblcounter
dblCounter = dblCounter + 1
Loop
Loop
'Run the text-to-columns wizard on both sheets.
For i = 1 To objDestWkBk.Sheets.Count
Sheets(i).Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=True, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1))
Sheets(i).Select
Cells.EntireColumn.AutoFit
Range("A1").Select
Next i
z = Sheets.Count
For x = 1 To z
A = Sheets(x).Range("A1").Value
Sheets(x).Name = Left(A, 25)
Next
Dim CurrentSheet As Object
' Loop through all selected sheets.
For Each CurrentSheet In Application.ActiveWorkbook.Sheets
' Delete top row of each sheet.
CurrentSheet.Range("a1").EntireRow.Delete
Next CurrentSheet
CleanUp:
Close
Application.StatusBar = False
Application.ScreenUpdating = True
If Err.Number <> 0 Then MsgBox "Error " & Err.Number & ": " & Err.Description
End Sub