I have an import routine that allows the user to browse for a fixed width file and select it for import. Everything on that portion works as planned. My issue comes with the rows. The first 2 characters of each row in the import file indicate a record type, I am really only interested in the rows with a record type of "12".
I have 2 questions;
Which would be a better method of selecting only "12" records, should I try to import only rows where the type is "12" or should I import all rows and then delete any row where column 1 is not a "12"?
Second question is how would I accomplish the suggested method.
For reference, I code I am using to import the file is below.
I have 2 questions;
Which would be a better method of selecting only "12" records, should I try to import only rows where the type is "12" or should I import all rows and then delete any row where column 1 is not a "12"?
Second question is how would I accomplish the suggested method.
For reference, I code I am using to import the file is below.
Code:
Sub ImportFile()
WEXImportSheet = "WEXImportSheet"
DataArray = Array(1, 9, 2, 2, 2, 9)
FieldArray = Array(2, 77, 8, 12, 40)
StartRow = 2
Sheets(WEXImportSheet).Select
' Original Code to remove existing named range, variable didn't work so I did it in the case statement for variable definition
' ActiveWorkbook.Names(OpisFileName).Delete
Range("B2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & WEXImportFile, _
Destination:=Range("$B$2"))
.Name = WEXFileName
.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 = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = DataArray
.TextFileFixedColumnWidths = FieldArray
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub