Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Transfering Required data from *.txt file to

I retriving data from the machine printer to the txt file using th
RS232 interface , all the data which I am getting is stored in th
*.txt file. I woul like to request for help as to how I can pick th
required data from txt file to excel sheet because if i simply ope
that *.txt file in exl the complete line forms only one cell (String
and numeric values comes in one cell only) where as I would like t
pick the numeric values only from that txt file. Can anybody help me i
writing the macro for that or can advise me as to how I can get th
numeric data only from the txt file to excel file.

I would like to mention one example:- the data I ge from the txt fil
in one cell is

" Total Production of day = 150 Kg."
" Total yarn cuts for 1000 meters = 120"

Now if I open this in excel, The complete one line comes in one cel
only where as in the above two lines I require "1000" from the fir
line and "120" from the second line ( I do not want any alphanumeric t
be picked along with that

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Transfering Required data from *.txt file to

Here's some code. Hasn't been through a lot of testing.
Probably would have been better using VBScript Regular Expression library.

Sub test()
Debug.Print GetLineNumeric(Replace(Range("A1").Value, """", ""), "=", 2)
End Sub

Function GetLineNumeric(Text As String, TextAfter As String, LineNum As
Long) As String
Const cLineSep = vbLf
Dim lngLine As Long, i As Long, j As Long, k As Long, strTemp As String,
strCandidate As String

lngLine = 1
i = 1
Do Until lngLine = LineNum
i = InStr(i, Text, cLineSep)
If i = 0 Then Exit Do Else i = i + 1
lngLine = lngLine + 1
Loop

If i 0 Then
j = InStr(i, Text, cLineSep)
strTemp = Mid(Text, i, IIf(j = 0, Len(Text) - i + 1, j - i))
i = InStr(1, strTemp, TextAfter)
If i 0 Then strTemp = Mid(strTemp, i + 1)
i = 1
Do Until i = 0
j = InStr(i, strTemp, " ")
strCandidate = Mid(strTemp, i, IIf(j = 0, Len(strTemp) + 1, j) -
i)
If IsNumeric(strCandidate) Then
GetLineNumeric = strCandidate
Exit Do
Else
i = j + 1
End If
Loop
End If
End Function


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Gurpreet " wrote in message
...
I retriving data from the machine printer to the txt file using the
RS232 interface , all the data which I am getting is stored in the
*.txt file. I woul like to request for help as to how I can pick the
required data from txt file to excel sheet because if i simply open
that *.txt file in exl the complete line forms only one cell (Strings
and numeric values comes in one cell only) where as I would like to
pick the numeric values only from that txt file. Can anybody help me in
writing the macro for that or can advise me as to how I can get the
numeric data only from the txt file to excel file.

I would like to mention one example:- the data I ge from the txt file
in one cell is

" Total Production of day = 150 Kg."
" Total yarn cuts for 1000 meters = 120"

Now if I open this in excel, The complete one line comes in one cell
only where as in the above two lines I require "1000" from the firt
line and "120" from the second line ( I do not want any alphanumeric to
be picked along with that.


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transfering data from a .pdf file to word and then to excel David Bateman Excel Worksheet Functions 1 February 19th 10 10:03 PM
transfering data between sheets Parker Jones Excel Discussion (Misc queries) 1 July 9th 09 10:44 PM
Automatically Transfering Data from Excel to Word file Ra Excel Discussion (Misc queries) 3 April 8th 09 01:20 PM
transfering data in another column entering more sorted data Kevin - Corporate Services Excel Worksheet Functions 0 August 6th 08 09:23 PM
Transfering data across worksheets GarToms Excel Discussion (Misc queries) 2 March 7th 06 01:31 PM


All times are GMT +1. The time now is 02:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"