Exporting a space delimited file from Excel

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
537
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a custom program that reads data from a space delimited (padded?) text file and performs a number of tasks for us, such as importing the data into our system. Starting next month, I will be receiving a second file from a separate system and need to consolidate the two files into one before running our program. I've managed to do that with macros and code I've pulled from the forum so I'm all set on that piece. My problem is I need to export the results using the same space specifications as the source files or else our program wont be able to process the file.

Can this be done from Excel? The specs from the source file are shown below with the column or field name and the starting and ending position for each field. Each line is 132 characters long with a carriage return/line feed at the end. Spaces need to be padded to the right of the value for each field. For example, the ITEM is always 10 characters long and need to be padded with a space after the field value. The TYPE is always one character and needs a space after each value. The VAL is either one or two characters and must be padded accordingly with either 4 or 5 spaces up to the 19th character. And so one for the remaining fields.
ABCDEF
ITEMTYPEVAL$QTYDESC
Start11214203341
End1113193240132

<tbody>
</tbody>
 
Earlier this morning I updated the code to select all six columns and formatted them as text with courier new as the font. I saved the output as formatted text and could have sworn the output looked fine. I had to make a few more changes just now so I modified the code and when I looked at the output I noticed the overall length varied on each line. The sixth field is the description and no longer has the padding after the description, the line just ends after the last character.
Just wondering if you saw the code I posted in Message #8 yet (you do not have to do anything with formatting or font selection using it)?
 
Last edited:
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Just wondering if you saw the code I posted in Message #8 yet (you do not have to do anything with formatting or font selection using it)?
So I removed those steps from the code and added Rick's code which I tested successfully several times.
Hi Rick I actually did end up using your code and it works great :). I was just curious as I thought I had the results I needed by doing the formatted text export but it seems I was mistaken and it never padded the final column. I don't plan on changing anything as it works as I needed. Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,683
Members
449,116
Latest member
HypnoFant

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