Hello griffinco,
The macro has been tested on the file you posted. When "BEGINSUB" is detected a new line is started with the first column containing what followed "BEGINSUB". A new column is filled on this row if the follow are found anywhere in the text: FLWSYM, PURPOSE, ns, /ns. These comparisons are case sensitive to avoid the "NS" in "BEGINSUB" from being the same as "ns" elsewhere. The "ns" string is expected to have zero or more characters after it followed by a colon. This was based on your file. If this needs to be changed, let know.
The macro assumes your will be copying the data to active sheet and starts with cell "A1". This can changed if needed. You will prompted o locate the file to be opened. This seems like a better option than hard coding the path and file name into the macro. Let me know if any changes need to be made or you have any problems.
' Thread: http://www.excelforum.com/excel-programming/833560-help-parsing-text-file-into-rows-and-columns-based-on-values.html
' Poster: griffinco
' Written: May 25, 2012
' Author: Leith Ross (www.excelforum.com)
Sub ParseTextFile()
Dim ColNum As Variant
Dim Filename As String
Dim fn As Integer
Dim RegExp As Object
Dim Rng As Range
Dim RowNum As Long
Dim T As Boolean
Dim Text As String
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set Rng = Wks.Range("A1")
Filename = Application.GetOpenFilename("Text Files (*.txt), All Files (*.*)", 1)
If Filename = False Then Exit Sub
Set RegExp = CreateObject("VBScript.RegExp")
RegExp.Pattern = "FLWSYM|ns.*\:|\/ns|PURPOSE"
fn = FreeFile
Open Filename For Input Access Read As #fn
Do While Not EOF(fn)
Line Input #fn, Text
If Text Like "BEGINSUB *" Then
RowNum = RowNum + 1: ColNum = 1
Rng.Item(RowNum, ColNum) = Right(Text, Len(Text) - 9)
End If
If RegExp.Test(Text) = True Then
ColNum = ColNum + 1
Rng.Item(RowNum, ColNum) = Text
End If
Loop
Close #fn
End Sub
Bookmarks