Try this:
Option Explicit
Sub ImportObjectList()
'Author: Jerry Beaucaire
'Date: 9/16/2010
'Summary: Import a text file and extract/format specific data
Dim fName As String
Dim LR As Long
'Select a file
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Filters.Add "All Files", "*.*" 'everything
.Filters.Add "Text Files", "*.txt", 1 'default
.Show
If .SelectedItems.Count > 0 Then
fName = .SelectedItems(1)
Else
Exit Sub
End If
End With
'Application.ScreenUpdating = False
'Import the file
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fName, _
Destination:=Range("A1"))
.Name = "ame--"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
'Delete unneeded rows
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("B1:B" & LR).FormulaR1C1 = _
"=IF(OR(ISNUMBER(SEARCH({""Name "",""Information on"",""SEGMENT LENGTH""}, RC[-1]))), RC[-1], 1)"
Columns("B:B").SpecialCells(xlCellTypeFormulas, 1).EntireRow.Delete
'Create new table
Range("A1").Insert xlShiftDown
Range("A1:C1").Value = [{"OBJECTS","NAME","SEGMENT LENGTH"}]
Range("B2:B" & LR).FormulaR1C1 = _
"=IF(LEFT(RC1,4)=""Info"",TRIM(MID(R[1]C1,6,LEN(R[1]C1))), """")"
Range("C2:C" & LR).FormulaR1C1 = _
"=IF(LEFT(RC1,4)=""Info"", TRIM(MID(R[2]C1,FIND(""="",R[2]C1)+2, LEN(R[2]C1)-FIND("" ("",R[2]C1)-2)), """")"
Columns("B:C").Value = Columns("B:C").Value
Range("A1").AutoFilter
Range("A1").AutoFilter Field:=2, Criteria1:="="
Range("A2:C" & LR).EntireRow.Delete xlShiftUp
ActiveSheet.AutoFilterMode = False
On Error Resume Next
Columns("A:C").SpecialCells(xlCellTypeConstants, 16).ClearContents
On Error GoTo 0
Columns("A:C").EntireColumn.AutoFit
Range("A1:C1").Font.Bold = True
Range("A2").Select
ActiveWindow.FreezePanes = True
Application.ScreenUpdating = True
End Sub
Bookmarks