Saving from excel to fixed width file

pmsteph

New Member
Joined
Oct 17, 2003
Messages
33
I need to save/copy data I have set up in Excel into a fixed width file for importing into a database.

Is this possible & how do I set it up so the columns are the correct widths?

Any help would be useful.
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
We could certainly automate this with VBA; and perhaps someone with time to do it will stop by. But in the meantime, here's a simply way to get you going.
  1. Create a row with your required widths. (Row 1 in my example.)
  2. Create a formula that concatenates the columns together, using the LEN() and REPT() functions to pad appropriately.
  3. Then you can copy the contents of your composite column over to NOTEPAD, paste in and save and your done.
book1
ABCDEF
15101081Composite
2aaBBBBBCCCCCCCDDDDDDZaa BBBBB CCCCCCC DDDDDD Z
3aBBCCCCCDZa BB CCCCC D Z
4AAAAbbbbbbbCcCcddddZAAAA bbbbbbb CcCc dddd Z
Sheet1


Formula in F2 and downwards: <ul>[*]=A2&REPT(" ",A$1-LEN(A2))&B2&REPT(" ",B$1-LEN(B2))&C2&REPT(" ",C$1-LEN(C2))&D2&REPT(" ",D$1-LEN(D2))&E2&REPT(" ",E$1-LEN(E2))[/list]

HTH
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
OK - this does actually work -- the problem is that the PHP software of this board strips out double spaces. So don't worry that column F doesn't look right in the posted example.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,736
Messages
5,573,921
Members
412,555
Latest member
mark84
Top