Dec 31st, 2012, 02:43 PM
Search text file for keywords and input information into excel columns
I am currently working on a program that can search through multiple text files and be able to search for certain Strings, obtain the information after the string, and put it into an excel document.
Weight: 200 lb
Weight: 170 lb
However, because the length of each text file differs and there is a lot of information in the text file that isn't required, I'd like to be able look for the Keywords: Name, Height, Weight, and output the information into excel columns.
Ideas on how to do this would be appreciated.
Jan 1st, 2013, 05:52 AM
Re: Search text file for keywords and input information into excel columns
Welcome to the forums smilestatue
If the names are unique, and the Height and the Weight is right below the Name always then you can try this method
1. Read the file in an array in one go
2. Loop through the array to find the name and then pick up the values.
Dim MyData As String, strData() As String
Dim Nm As String, Ht As String, Wt As String
Dim i As Long
Open "C:\Sample.Txt" For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
strData() = Split(MyData, vbCrLf)
Nm = "Kevin"
For i = LBound(strData) To UBound(strData)
If Trim(strData(i)) = "Name: " & Trim(Nm) Then
Ht = strData(i + 1)
Wt = strData(i + 2)
Debug.Print Nm: Debug.Print Ht: Debug.Print Wt
The poster formerly known as koolsid
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ
Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011
Click Here to Expand Forum to Full Width