Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Extracting information from more than 1 text files

Hi All,
I daily save 10 to 20 text files which contain the following info:

Site XXXXXXX installed:
Master Cab Serial No: SWxxxxxxx
Master Cab PartNo: X7xxxxxxx

Slave Cab Serial No: Swxxxxxxx
Slave Cab Part No: Swxxxxxxxx

Issues: rectifier is faulty.
Team : workerA and WOrkerB (Names)

I want to make a macro which when run, open the files one by one, extracts
the Site Name, serial number, part number and issue from the file and save in
my Excel Sheet. in C1,D1,E1,F1 etc.

Site Name can be of different length but part number is 7 digits long and
serial number is 10 digits, ofcourse issues can be of any lenght.
WOuld you please spare some time and prepare code for this.
I shall be grateful to you.
Regards,
Junaid

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Extracting information from more than 1 text files

Junaid,

If your files are _exactly_ the same as what you posted, then copy all the code into a codemodule of
an otherwise blank workbook, and run the macro ReadDataFromFiles.

HTH,
Bernie
MS Excel MVP

Option Explicit
Dim myVals(1 To 7) As String

Sub ReadDataFromFiles()
Dim i As Integer
Dim FileArray As Variant
Dim myFilename As String
FileArray = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(FileArray) Then
For i = LBound(FileArray) To UBound(FileArray)
myFilename = FileArray(i)
ReadFileData myFilename
Cells(Rows.Count, 1).End(xlUp)(2).Resize(1, 7).Value = myVals
Next i
Else:
MsgBox "You clicked cancel"
End If
End Sub


Function ReadFileData(FileName As String)
'Dimension Variables
Dim ResultStr As String
Dim FileNum As Integer
Dim Counter As Double

FileNum = FreeFile()
Open FileName For Input As #FileNum
Application.ScreenUpdating = False
'Read first line
Line Input #FileNum, ResultStr
myVals(1) = Split(ResultStr, " ")(1)
Line Input #FileNum, ResultStr
myVals(2) = Split(ResultStr, " ")(4)
Line Input #FileNum, ResultStr
myVals(3) = Split(ResultStr, " ")(3)
Line Input #FileNum, ResultStr
Line Input #FileNum, ResultStr
myVals(4) = Split(ResultStr, " ")(4)
Line Input #FileNum, ResultStr
myVals(5) = Split(ResultStr, " ")(4)
Line Input #FileNum, ResultStr
Line Input #FileNum, ResultStr
myVals(6) = Mid(ResultStr, InStr(1, ResultStr, ": ") + 2, Len(ResultStr))
Line Input #FileNum, ResultStr
myVals(7) = Mid(ResultStr, InStr(1, ResultStr, ": ") + 2, Len(ResultStr))

Close
End Function





"Telecommm" wrote in message
...
Hi All,
I daily save 10 to 20 text files which contain the following info:

Site XXXXXXX installed:
Master Cab Serial No: SWxxxxxxx
Master Cab PartNo: X7xxxxxxx

Slave Cab Serial No: Swxxxxxxx
Slave Cab Part No: Swxxxxxxxx

Issues: rectifier is faulty.
Team : workerA and WOrkerB (Names)

I want to make a macro which when run, open the files one by one, extracts
the Site Name, serial number, part number and issue from the file and save in
my Excel Sheet. in C1,D1,E1,F1 etc.

Site Name can be of different length but part number is 7 digits long and
serial number is 10 digits, ofcourse issues can be of any lenght.
WOuld you please spare some time and prepare code for this.
I shall be grateful to you.
Regards,
Junaid



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Extracting information from more than 1 text files


Thanks Dear.
It works fine for me.
Thanks for the support.
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
Extracting data from large text files for beginner [email protected] Excel Worksheet Functions 1 November 12th 08 09:23 AM
Extracting information Paula Excel Worksheet Functions 1 April 4th 07 03:14 PM
Extracting certain information from cells RobMack Excel Worksheet Functions 9 February 15th 06 02:37 AM
extracting information from workbook to another pauluk Excel Programming 1 January 21st 04 06:55 PM
Excel and Text Files - Extracting MrAlMackay Excel Programming 1 September 14th 03 09:07 PM


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

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

About Us

"It's about Microsoft Excel"