Give this a try:
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
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("B1:B" & LR).FormulaR1C1 = _
"=IF(OR(ISNUMBER(SEARCH({""Information on"",""SEGMENT LENGTH""}, RC[-1]))), RC[-1], 1)"
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeFormulas, 1).Select
Selection.EntireRow.Delete
Range("A1").Insert xlShiftDown
Columns("B:B").Value = Columns("B:B").Value
Range("A1:B1").Value = [{"OBJECTS","SEGMENT LENGTH"}]
Columns("B:B").Replace What:="SEGMENT LENGTH = ", Replacement:="", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").AutoFilter Field:=1, Criteria1:="=SEGMENT*"
Range("A2:A" & LR).EntireRow.Delete xlShiftUp
Range("A1").AutoFilter
Range("A1").AutoFilter Field:=2, Criteria1:="=Informa*"
Range("B2:B" & LR).ClearContents
ActiveSheet.AutoFilterMode = False
Columns("A:B").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Range("A1:B1").Font.Bold = True
Range("A2").Select
ActiveWindow.FreezePanes = True
Application.ScreenUpdating = True
End Sub
Bookmarks