Importing txt file with multiple headers

Droopy

New Member
Joined
Aug 25, 2003
Messages
10
I'm trying to import a .txt file that has 3 lines of headings on every 'page'. I don't need to import the headers and just want the actual data to line up into columns. Is it possible to bypass these header rows on import?

e.g. This is an example of the text file:

----- PFD ----- YEAR TO DATE TRIAL BALANCE: AUGUST 03 PAGE 1
ABCDEF/S 2300.1 THIS MONTH IS STILL OPEN 22/08/03 09:30
-------------------------------------------------------------------------------------
ACCOUNT TYPE DESCRIPTION DEBIT CREDIT
-------------------------------------------------------------------------------------
ACCOUNT A1

------------------------ ------------------------
.00 .00
===========================
LEDGER IN BALANCE
LEDGER IN BALANCE
----- PFD ----- YEAR TO DATE TRIAL BALANCE: AUGUST 03 PAGE 2
ABCDE/S 2300.1 THIS MONTH IS STILL OPEN 22/08/03 09:30
-------------------------------------------------------------------------------------
ACCOUNT TYPE DESCRIPTION DEBIT CREDIT
------------------------------------------------------------------------------------- ACCOUNTB AB 1234567-0 P DESCRIPTION1 ACCOUNT 1,326.48
AB 8357602-0 B DESCRIPTION2 2,762,722.86
AB 0834053-0 P DESCRIPTION3 300.00
AB 0384992-0 B DESCRIPTION5 2,617,277.64
 
And here's a small sample of the file using the Excel HTML add-in:
sample.txt
ABCD
1-----JSW-----YEARTODATETRIALBALANCE:AUGUST03PAGE2
2MPFNTB/S2300.1THISMONTHISSTILLOPEN22/08/0309:30
3------------------------------------------------------------------------------------------------------------------------------------
4ACCOUNTTYPEDESCRIPTIONDEBITCREDIT
5------------------------------------------------------------------------------------------------------------------------------------
6MESOPOTAMIA
7AU0007416-0PEXAMPLEDESCRIPTION1,326.48
8AU0009535-0BEXAMPLEDESCRIPTION2,762,722.86
9AU0022208-0PEXAMPLEDESCRIPTION6,135.75
10AU0022246-0PEXAMPLEDESCRIPTION3,405.00
11-----JSW-----YEARTODATETRIALBALANCE:AUGUST03PAGE4
12MPFNTB/S2300.1THISMONTHISSTILLOPEN22/08/0309:30
13------------------------------------------------------------------------------------------------------------------------------------
14ACCOUNTTYPEDESCRIPTIONDEBITCREDIT
15------------------------------------------------------------------------------------------------------------------------------------
16MESOPOTAMIA
17AU0907316-0PEXAMPLEDESCRIPTION5,830.75
18AU0907844-0PEXAMPLEDESCRIPTION1,624.88
19------------------------------------------------
2063,355,499.6264,510,104.90
21================================================
22OUTOFBALANCE.001,154,605.28
23-----JSW-----YEARTODATETRIALBALANCE:AUGUST03PAGE5
24MPFNTB/S2300.1THISMONTHISSTILLOPEN22/08/0309:30
25------------------------------------------------------------------------------------------------------------------------------------
26ACCOUNTTYPEDESCRIPTIONDEBITCREDIT
27------------------------------------------------------------------------------------------------------------------------------------
28CANADA
sample
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I think that you will have to do this with brute force; this is not a table with headers but a formatted report. You will need to check several copies of the reports to see that the formatting is consistent!

I think that the way to do it is to read the file in one line at a time.
Check for the 21 spaces that precede your data line.
Then double check that it is data by looking for the <2 Letters, Space, 7 digits, hyphen, 1 digit> pattern.
On finding the first data line you will know the previous line was your group header.
Keep checking and saving lines until that block of data ends.
Start looking for a new block of data, remembering that the line before will be your group header.

You will need to look for rules to split your data line; hopefully your credit/debit amount will either start or end at a fixed number of characters in from the start of the line.

Without a more detailed look at the actual text file it is a job to try to pull out patterns that can be used as rules.

HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

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