Convert Excel Spreadsheet into Fixed Character Width Data Se

lui

New Member
Joined
Aug 22, 2002
Messages
10
Hello,

I'm trying to convert my excel spreadsheet into a fixed character width data set. That is, column 1 should be 6 characters long, column 2 should be 20 characters long, etc. Can anybody shed some light into this? Much thanks.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi William:

Welcome to the Board!. I read that you want to have your data in a spreadsheet that has two columns, column A should be 6 characters wide, and column B should be 20 characters wide. What is your data -- do you already have some data; does it still have to be created; do you have it on paper.

It would be helpful to post as much information as you can provide. Also, the more specific your question, the better the chances of your getting meaningful help.

Regards!

Yogi
This message was edited by Yogi Anand on 2002-08-23 17:14
 
Upvote 0
Thanks for the message Yogi.

Currently I have an excel spreadsheet with six columns of data. Three columns are formatted in text and the other three in numbers. My objective is to save/export the data into a fixed width ascii format. The first three columns will be six characters long and the other three twenty. An example is shown below.

[6 spaces][6 spaces][6 spaces][20 spaces]...

I know how to export the excel data into tab-delimited format, but exporting/saving into a fixed-width ascii format is another issue. Thanks very much for your help. This is a great forum!

Best Regards,

William Lui
 
Upvote 0
Hi
Not too sure on exactly what you want your output to be? Continuous or with returns?
The following macro would take the example data from the worksheet below and create a textfile such as is listed below this spreadsheet. You may need to adjust the starting row. The rows which will be sent to the textfile are determined by column A and the data it contains or does not. If there are blank cells in between the first row of data to the last, in column A, then note this fact in a repy and someone will edit the code if you are unable.
FixedSave.xls
ABCDEFG
1123123123abcabcabc
2123123123abcabcabc
3123123123abcabcabc
4
5
Sheet1
<pre>
Sub ToText()
Dim f As Integer, fileToSave, r As Long
Dim abc(1 To 3) As String * 6, def(4 To 6) As String * 20
fileToSave = Application.GetSaveAsFilename
r = 1 'first row
f = FreeFile
Open fileToSave For Output As #f
Do
abc(1) = Cells(r, 1).Value: def(4) = Cells(r, 4).Value
abc(2) = Cells(r, 2).Value: def(5) = Cells(r, 5).Value
abc(3) = Cells(r, 3).Value: def(6) = Cells(r, 6).Value
Print #f, abc(1) & abc(2) & abc(3) & def(4) & def(5) & def(6)
r = r + 1
Loop While Not Cells(r, 1).Value = ""
Close #f
End Sub</pre>
Tom


PS. I forgot this. The textfile created from the above...<pre>
123 123 123 abc abc abc
123 123 123 abc abc abc
123 123 123 abc abc abc</pre>
This message was edited by TsTom on 2002-08-24 17:34
 
Upvote 0
Thanks Tom for the reply. Your script worked great with my data. I will let the forum know if I run into any problems. Thanks again.

Will
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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