Retreiving data from a fixed-width (non delimited) Flat-File based on criteria...

Klelvin

New Member
Joined
Oct 7, 2008
Messages
47
Hi,

Firstly, I'm wondering if this is possible in Excel VBA (2007 Windows xp):

I have a number of flat-files (no extension, but can convert them to txt if its easier) which contain account records in the following format:

TITLE of the FILE
001CRTA845461230022 NAME Address Amount
001CRTB898654230022 NAME Address Amount

for each record. The columns are split by fixed width (not tab / space delimited).

I need to have some VBA that will go through the file and firstly count the number of lines (which I can then minus 1 from to find out the number of records). Then Return the total of the amounts for all records. Then return the total of the amounts for all records with CRTA in the first field, then the total of the amounts for all records with CRTB in the first field.

Is this possible? And what do you think the best way to go about it would be? (I'm quite happy just to return the values to A1, B1, C1 etc)

I'm not necessarily asking for a coded solution, just some indication of posibility and how.

Thanks in advance

Owen
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi Owen:

Total amount for all records:
=SUM(D:D)

Total for CRTA:
=SUMIF(A:A,"*CRTA*",D:D)

Total for CRTB:
=SUMIF(A:A,"*CRTB*",D:D)
 
Upvote 0
Thanks Jon,

Unfortunately my formatting was removed from the above post and I didnt realise.

The data in the "columns" in the flat file is split by anything from 6 - 30 spaces (as opposed to the 1 space shown above) depending on the length of the address. This means that on an import, you have to manually choose text to columns and fixed width as a seperator before you get the data. Unfortunately the fixed width will then vary based on length of name and address.

I will be experimenting with importing the data and auto manipulation (but due to spaces in the name and address field any delimiting by spaces doesnt work either) but I would really like it to read from the file itself if possible.

Thanks again.

OWen
 
Upvote 0

Forum statistics

Threads
1,215,851
Messages
6,127,291
Members
449,374
Latest member
analystvar

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