Opening Multiple CSV files and Parsing for Specific keywords

FNG2Excel

New Member
Joined
Jul 23, 2011
Messages
2
I'm trying to use Excel file to open multiple text files ( all files are in the same directory ) and parse for specific key words. I'm trying to list the name of files to be processed in worksheet Files cells E10 to end of files listed below.
I'm trying to parse these files for specific keywords like XX-0039 and then paste the information from that line into different cells of withing worksheet Data. Unfortunately I cannot get this script to open more that 1 file ie. Files listed in cells E11,E12..etc...
Can someone please help me...



Public Sub GetData()

Dim NumRows As Integer
Dim x As Integer
Dim y As String
Dim strDirectory As String
Dim strFile As String
Dim lngS As Long 'row count variable in data worksheet for processing events
Dim data As String 'data variable for reading text files
Dim test As String
Dim error_code As String

lngS = 2

lngCalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
DoEvents

strDirectory = ActiveWorkbook.Path & "\"

'Clear out the old
Sheets("Data").Activate
Range("A6:c65000").ClearContents
k = 2
lngS = k + 4

Worksheets("Files").Activate

NumRows = Range("E65536").End(xlUp).row

For x = 10 To NumRows

strFile = Cells(x, 5).Value
strFile = strDirectory + strFile


'Filter the tool text file
Open strFile For Input As #1

Do While Not EOF(1)
Line Input #1, data

test = Mid(data, 14, 7)

If Mid(data, 14, 7) = "XX-0039" Or Mid(data, 14, 7) = "33-0052" Or Mid(data, 14, 7) = "XY-5953" Then
Sheets("Data").Activate

a = Replace(data, vbTab, "")

error_code = Trim(Mid(a, 14, 7))
event_name = Trim(Mid(a, 12, 999))
eventtime = Trim(Mid(a, 23, 28))


Range(CStr("a" & lngS)).Value = event_name
Range(CStr("b" & lngS)).Value = eventtime
Range(CStr("c" & lngS)).Value = error_code


lngS = lngS + 1
End If

DoEvents
Loop

Close #1
Next

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
:confused:BTW I just realized that I'm able to open/parse multiple small files but not large files ( eg a 17MB csv file )...but not all the time..I've managed to open a few small files by pressing F8 to step thru the files. However this does not work all the time..I'm really confused now..:(
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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