Here's my version. Not nearly as compact as patel45.
Sub ImportData()
Dim WS As Worksheet
Dim aCol As Long
Dim NextRow As Long
Dim FileToOpen As String
Dim TextLine As String
Dim Temp As Variant
FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
Set WS = ActiveSheet
With WS
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
If FileToOpen <> "" Then
Open FileToOpen For Input As #1
Do
Line Input #1, TextLine
If InStr(TextLine, "#BEGIN") > 0 Then
aCol = 1
Temp = Split(TextLine)
WS.Cells(NextRow, aCol) = Temp(UBound(Temp))
Do
Line Input #1, TextLine
If TextLine Like ("[#]*:") Then
Line Input #1, TextLine
aCol = aCol + 1
WS.Cells(NextRow, aCol) = TextLine
End If
Loop Until EOF(1) Or InStr(TextLine, "#END") > 0
End If
NextRow = NextRow + 1
Loop Until EOF(1)
Close #1
End If
End With
End Sub
Bookmarks