Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Transfering data from a .pdf file to word and then to excel | Excel Worksheet Functions | |||
transfering data between sheets | Excel Discussion (Misc queries) | |||
Automatically Transfering Data from Excel to Word file | Excel Discussion (Misc queries) | |||
transfering data in another column entering more sorted data | Excel Worksheet Functions | |||
Transfering data across worksheets | Excel Discussion (Misc queries) |