.txt In .xls out Macro
very sorry for posting imcomplete one. i forgot to attach two auxiliay functions.
this is full one.
Sub testdo()
Dim exflname
Dim i As Long, k As Long
Dim filenum1
Dim textline As String
Dim Words
Dim findword As Boolean
Const word1 = "Distribution"
Const word2 = "Mean"
MsgBox "select data file"
exflname = Application.GetOpenFilename
If exflname = False Then
MsgBox "file not selected"
Exit Sub
End If
filenum1 = FreeFile()
Open exflname For Input As #filenum1
k = 1
Do While Not EOF(filenum1)
Line Input #1, textline
Words = Getwords(textline)
i = LBound(Words)
Do While (i <= UBound(Words))
If findspword(Words(i), word1) Then
i = i + 1
If findspword(Words(i), word2) Then
i = i + 1
Do While (i <= UBound(Words))
If IsNumeric(Words(i)) Then
Cells(k, "b") = Words(i)
k = k + 1
Exit Do
End If
i = i + 1
Loop
End If
End If
i = i + 1
Loop
Loop
Close #filenum1
End Sub
Function findspword(ByVal s As String, ByVal spword As String) As Boolean
If s = spword Then
findspword = True
Else
findspword = False
End If
End Function
Function Getwords(ByVal s) As Variant
Getwords = split(Application.Trim(Application.Clean(s)), " ")
End Function
keizi
"kounoike" wrote in message
...
it seems very diffrent one from your first post to me.
if the format is uniform, it could be written more simple and smart way.
but try this, if you don't mind.
"Telecommm" wrote in message
...
Hi,
Please have a look on the following text:
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 0
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 0
MEAS_TYPE : PATH_BALANCE
Distribution Mean : 110
Distribution Max. : 123
Distribution Min. : 83
Bin : 0 0 0 1 1394 1425 0 0 0 0
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 1
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 1
MEAS_TYPE : PATH_BALANCE
Distribution Mean : 106
Distribution Max. : 134
Distribution Min. : 90
Bin : 0 0 0 0 1840 731 3 0 0 0
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 2
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 2
MEAS_TYPE : PATH_BALANCE
Distribution Mean : 111
Distribution Max. : 120
Distribution Min. : 88
Bin : 0 0 0 1 908 2228 0 0 0 0
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 3
SITE : 4 CELL #: LAC=029Ah CI=E2B9h
RTF ID : 0 3
MEAS_TYPE : PATH_BALANCE
Distribution Mean : 106
Distribution Max. : 121
Distribution Min. : 89
Bin : 0 0 0 1 914 283 0 0 0 0
I want to extract the number after the word "Distribution Mean" ( in last
group its 106).
Thanks a lot for the replies.
Best Regards,
|