Fixed Import of Specific Rows

Nighabi

New Member
Joined
Feb 13, 2008
Messages
34
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.
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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
1) Import the data to a blank sheet (your existing code does this, I presume)
2) Insert a blank row1
3) Insert a header into A1
4) Turn on the Autofilter in row 1
5) Filter column A for "does not equal 12"
6) Delete all visible rows
7) Turn off autofilter and delete added row1

Now you have your "12" items only on the new sheet.
 
Upvote 0
Thanks, that would be an option for a work around. I left out that later in the code I automatically save the file and that file is used as a source from reporting. I'm trying to remove as much user interaction as I can. I was hoping to remove all but the "12" programatically.
 
Upvote 0
Well, the steps above can be all be accomplished programmatically, too. Use the macro recorder to get the base code, then adapt it into your macro as a whole. Post your pseudo code here if you need help adapting it.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top