Code:
Sub import_Text_File() Dim fs As Object
Dim txtIn As Object
Dim strFile As String
Dim strLine As String
Dim A As Date
Dim B As String
Dim C As String, D As String, E As String, F As String
Dim iRow As Integer
Dim spath As String
Dim oFSO As Object
Application.ScreenUpdating = False
Cells.Clear
Set fs = CreateObject("scripting.FileSystemObject")
iRow = 2
strFile = "C:\Users\muhammad.zubair\Downloads\LP & PG EU April 2014\PG\41512008.lp"
Set txtIn = fs.openTextFile(strFile, 1) ' 1 ForReading
Do While Not txtIn.AtEndOfStream
strLine = txtIn.ReadLine
If InStr(1, strLine, "MWh") Or InStr(1, strLine, "ISKMT") Then
strLine = Delete
ElseIf InStr(1, strLine, "P.01") Then
A = DateSerial(Mid(strLine, 6, 2), Mid(strLine, 8, 2), Mid(strLine, 10, 2))
B = TimeSerial(Mid(strLine, 12, 2), Mid(strLine, 14, 2), 0)
strLine = Delete
Else
C = Val(Mid(strLine, 2, 9))
D = Val(Mid(strLine, 13, 9))
E = Val(Mid(strLine, 24, 10))
F = Val(Mid(strLine, 35, 10))
G = A + B
Cells(iRow, 1) = A
Cells(iRow, 2) = B
Cells(iRow, 2).NumberFormat = "HH:MM"
Cells(iRow, 3) = C
Cells(iRow, 4) = D
Cells(iRow, 5) = E
Cells(iRow, 6) = F
Cells(iRow, 7) = G
Cells(iRow, 7).NumberFormat = "dd-mmm-yyyy hh:mm"
B = (Cells(iRow, 2) + 1 / 24 / 2)
iRow = iRow + 1
End If
Loop
Cells(1, 1) = "Date"
Cells(1, 2) = "Time"
Cells(1, 3) = "L1R2"
Cells(1, 4) = "L1R1"
Cells(1, 5) = "L1R4"
Cells(1, 6) = "L1R3"
Cells(1, 7) = "Time Stamp"
Columns.AutoFit
Application.ScreenUpdating = True
End Sub