Solved

Set column breaks when importing a text file into Excel

Posted on 2014-04-08
2
222 Views
Last Modified: 2014-04-15
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
Comment
Question by:dbfromnewjersey
2 Comments
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 39985723
Post the sample file to help experts.
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39985791
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now