Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Set column breaks when importing a text file into Excel

I have a text file which is effectively a report that I need to import into Excel. In addition to the records I need, the file has a lot of other garbage (unneeded records, headers, page numbers, summary totals, etc).

Because this is a routine I have to do often, I'm getting tired of having to make manual adjustments in the text import wizard window. Plus, it's very time consuming.

Regarding the records I'm interested in, the data I need is always in the same position in the source file. What I mean by that is that (from left to right), I need bytes 1 thru 10 to be its own column, bytes 23 thru 35 to be its own column, bytes 54 thru 63 to be  its own column and bytes 64 thru 106.  I don't care about any of the other data.  It's ok if it gets imported into one or more other columns or not. I can get rid of the unnecessary data later on in a clean up procedure.  Is there a macro that can accomplish this?  One of my main issues is not knowing whether blank areas in a text file are made up of spaces or not. Thanks.
0
dbfromnewjersey
Asked:
dbfromnewjersey
1 Solution
 
Raheman M. AbdulCommented:
Post the sample file to help experts.
0
 
Rgonzo1971Commented:
Hi,
pls try

    Workbooks.OpenText Filename:= _
        "c:\Documents\YourFile.txt", Origin:=437 _
        , StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array( _
        10, 9), Array(23, 1), Array(35, 9), Array(54, 1), Array(63, 1), Array(106, 9)), _
        TrailingMinusNumbers:=True

Open in new window

Regards
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now