PatrickM,
Sorry for the delayed response. Attached is a test text file that contains the test data you provided. Also attached is an example workbook that can be used to import the text file information in the desired format. The 'Import Text File' button is mapped to this macro:
Sub tgr()
Dim strTxtPath As String
Dim arrLine() As String
Dim arrData() As String
Dim LineIndex As Long, DataIndex As Long, ColIndex As Integer
Dim strTemp As String
strTxtPath = Application.GetOpenFilename("Text Files, *.txt")
If strTxtPath = "False" Then Exit Sub
ActiveSheet.UsedRange.Offset(1).Clear
ReDim arrLine(1 To Rows.Count)
ReDim arrData(1 To 4, 1 To Rows.Count)
Close #1
Open strTxtPath For Input As #1
Do While Not EOF(1)
LineIndex = LineIndex + 1
Line Input #1, arrLine(LineIndex)
strTemp = Replace(Replace(Replace(Replace(arrLine(LineIndex), "(", ""), ")", ""), " ", ""), "-", "")
If Len(strTemp) = 10 And IsNumeric(strTemp) Then
DataIndex = DataIndex + 1
arrData(1, DataIndex) = arrLine(LineIndex - 3)
arrData(2, DataIndex) = arrLine(LineIndex - 2)
arrData(3, DataIndex) = arrLine(LineIndex - 1)
arrData(4, DataIndex) = arrLine(LineIndex - 0)
LineIndex = 0
End If
Loop
Close #1
If DataIndex > 0 Then
ReDim Preserve arrData(1 To 4, 1 To DataIndex)
Range("A2:D2").Resize(DataIndex).Value = Application.Transpose(arrData)
End If
Erase arrData
Erase arrLine
End Sub
Just in case you are new to macros:
How to use a macro:- Make a copy of the workbook the macro will be run on
- Always run new code on a workbook copy, just in case the code doesn't run smoothly
- This is especially true of any code that deletes anything
- In the copied workbook, press ALT+F11 to open the Visual Basic Editor
- Insert | Module
- Copy the provided code and paste into the module
- Close the Visual Basic Editor
- In Excel, press ALT+F8 to bring up the list of available macros to run
- Double-click the desired macro (I named this one tgr)
Bookmarks