importing from *.txt file by automation!

TPPICORNELL

New Member
Joined
Jan 24, 2003
Messages
4
Dear all,

At our hospital here we have a problem in importing data on an excel workbook for a file in format .txt.

In fact, we need to import automatically via a browser a file in .txt format, and when there is a numerical value in a sentence, this value has to be fixed in a precise cell, without any others characters than numerical values.


Thanks a lot for any help!

TPP

Here is the typical file:
time temp text °C = 20.8 patient Erika Trinkler
0 29.9
0.2 29.8
0.4 30.1
0.6 30.1
0.8 30.4
1 30.5
1.2 30.7
1.4 30.7
1.6 30.9
1.8 30.8
2 30.8
2.2 30.9
2.4 30.9
2.6 30.9
2.8 31
3 31
3.2 31
3.4 31.2
3.6 31.2
3.8 31.1
4 31.2
4.2 31.3
4.4 31.4
4.6 31.3
4.8 31.2
5 31.4
5.2 31.4
5.4 31.5
5.6 31.4
5.8 31.3
6 31.4
6.2 31.3
6.4 31.4
6.6 31.4
6.8 31.5
7 31.5
7.2 31.5
7.4 31.5
7.6 31.5
7.8 31.6
8 31.5
8.2 31.7
8.4 31.5
8.6 31.7
8.8 31.6
9 31.7
9.2 31.7
9.4 31.8
9.6 31.7
9.8 31.6
10 31.7
10.2 31.7
10.4 31.7
10.6 31.6
10.8 31.7
11 31.7
11.2 31.8
11.4 31.8
11.6 31.7
11.8 31.7
12 31.8
12.2 31.9
12.4 31.8
12.6 31.8
12.8 31.9
13 31.9
13.2 31.7
13.4 31.9
13.6 31.7
13.8 32
14 31.8
14.2 32
14.4 32
14.6 31.9
14.8 32
15 31.9
15.2 31.9
15.4 31.8
15.6 32.1
15.8 31.9
16 32
16.2 32
16.4 32.2
16.6 32.1
16.8 31.9
17 32
17.2 32
17.4 32.2
17.6 32
17.8 32
18 32.2
18.2 32.1
18.4 32.2
18.6 32.2
18.8 32.1
19 32.2
19.2 32.2
19.4 32
19.6 32.2
19.8 32.1
20 32.2
20.2 32.2
20.4 32
20.6 32.2
20.8 32
21 32.1
21.2 32.1
21.4 32.2
21.6 32.2
21.8 32.2
22 32.3
22.2 32.2
22.4 32.2
22.6 32.3
22.8 32
23 32.2
23.2 32.2
23.4 32.2
23.6 32.2
23.8 32.2
24 32.1
24.2 32.1
24.4 32.3
24.6 32.3
24.8 32.4
25 32.4
25.2 32.2
25.4 32.2
25.6 32.3
25.8 32.4
26 32.3
26.2 32.4
26.4 32.3
26.6 32.3
26.8 32.4
27 32.4
27.2 32.1
27.4 32.2
27.6 32.2
27.8 32.2
28 32.4
28.2 32.4
28.4 32.3
28.6 32.2
28.8 32.3
29 32.4
29.2 32.3
29.4 32.3
29.6 32.2
29.8 32.3
30 32.5
30.2 32.5
30.4 32.5
30.6 32.3
30.8 32.3
31 32.2
31.2 32.4
31.4 32.3
31.6 32.3
31.8 32.3
32 32.2
32.2 32.4
32.4 32.2
32.6 32.4
32.8 32.4
33 32.4
33.2 32.3
33.4 32.4
33.6 32.3
33.8 32.3
34 32.3
34.2 32.3
34.4 32.3
34.6 32.5
34.8 32.4
35 32.6
35.2 32.4
35.4 32.4
35.6 32.3
35.8 32.5
36 32.4
36.2 32.4
36.4 32.4
36.6 32.5
36.8 32.4
37 32.5
37.2 32.3
37.4 32.5
37.6 32.4
37.8 32.5
38 32.5
38.2 32.6
38.4 32.6
38.6 32.7
38.8 32.4
39 32.5
39.2 32.5
39.4 32.5
39.6 32.4
39.8 32.5
40 32.7
40.2 32.4
40.4 32.4
40.6 32.6
40.8 32.5
41 32.5
41.2 32.5
41.4 32.4
41.6 32.6
41.8 32.5
42 32.4
42.2 32.6
42.4 32.5
42.6 32.3
42.8 32.4
43 32.5
43.2 32.5
43.4 32.5
43.6 32.6
43.8 32.5
44 32.4
44.2 32.4
44.4 32.5
44.6 32.6
44.8 32.5


Datei Erstellt am: 10.01.2003 um 08:29:25

Patienten-Nummer: 4001
Untersuchung: 4; 10.01.2003 08:27:25
Name: Trinkler
Vorname: Erika
Adresse: -
Postleitzahl / Ort: - basel
Geburtsdatum / Alter: 01.11.1962 41
Geschlecht: weiblich
Ethnie: Kaukasisch
Blutdruck: 154 zu 99
Pulsfrequenz: 64
Auge: linkes Auge
Tonometriewert: 14 mmHg
Beobachtername: picornell
Kommentar: missing data: IOP mmHg <R>=13 <L>=17

Relative Luftfeuchtigkeit: 18 %
Temperatur bei Start Kühlung: 33.6 °C
Temperatur bei Stopp Kühlung: 29.9 °C
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi, I dont think is going to be easy to fix. The issue is theres no clear delimiter that can be used, so its a matter of importing and trying to sort out the data into columns afterwards.

If the numbers where across the page rather than underneath text it would be easier. Where do you get the data for the text files - is this downloaded from a mainframe or database? If so, perhaps the fields could be delimited with some obscure character, like a tilde (~) when the text file is created.
 
Upvote 0
Hello, Good morning,

Yes, exactly, there are characters like "ung:"
and " °C" before and after the numerical value!


Greetings,

TPP
On 2003-01-27 05:04, parry wrote:
Hi, I dont think is going to be easy to fix. The issue is theres no clear delimiter that can be used, so its a matter of importing and trying to sort out the data into columns afterwards.

If the numbers where across the page rather than underneath text it would be easier. Where do you get the data for the text files - is this downloaded from a mainframe or database? If so, perhaps the fields could be delimited with some obscure character, like a tilde (~) when the text file is created.
 
Upvote 0
to extract the text file to excel, use:

Sub LargeFileImport()

'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
'Ask User for File's Name
FileName = InputBox("Please enter the Text File's name, e.g. S:RevenueStrausBATCHOCCMUM121002.txt")
'Check for no entry
If FileName = "" Then End
'Get Next Available File Handle Number
FileNum = FreeFile()
'Open Text File For Input
Open FileName For Input As #FileNum
'Turn Screen Updating Off
Application.ScreenUpdating = False
'Create A New WorkBook With One Worksheet In It
Workbooks.Add template:=xlWorksheet
'Set The Counter to 1
Counter = 1
'Loop Until the End Of File Is Reached
Do While Seek(FileNum) <= LOF(FileNum)
'Display Importing Row Number On Status Bar
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & FileName
'Store One Line Of Text From File To Variable
Line Input #FileNum, ResultStr
'Store Variable Data Into Active Cell
If Left(ResultStr, 1) = "=" Then
ActiveCell.Value = "'" & ResultStr
Else
ActiveCell.Value = ResultStr
End If

'For xl97 and later change 16384 to 65536
If ActiveCell.row = 65536 Then
'If On The Last Row Then Add A New Sheet
ActiveWorkbook.Sheets.Add
Else
'If Not The Last Row Then Go One Cell Down
ActiveCell.Offset(1, 0).Select
End If
'Increment the Counter By 1
Counter = Counter + 1
'Start Again At Top Of 'Do While' Statement
Loop
'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub




To extract the number from the text row, use:

Function ExtractNumber(rCell As Range)
Dim iCount As Integer, i As Integer
Dim sText As String
Dim lNum As String

''''''''''''''''''''''''''''''''''''''''''
'Extracts a number from a cell containing text and numbers.
'eg" 12wwr800gege257ergerg14 = 1280025714
''''''''''''''''''''''''''''''''''''''''''
sText = rCell

For iCount = Len(sText) To 1 Step -1
If IsNumeric(Mid(sText, iCount, 1)) Then
i = i + 1
lNum = Mid(sText, iCount, 1) & lNum
End If

If i = 1 Then lNum = CInt(Mid(lNum, 1, 1))
Next iCount

ExtractNumber = CLng(lNum)
End Function

( pls note that the function will be seen in the paste function option )
 
Upvote 0

Forum statistics

Threads
1,216,086
Messages
6,128,734
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top