Justify Excel Worksheet content when exporting to text file

JamesgTx

New Member
Joined
Jan 6, 2010
Messages
25
I have a macro that exports cell data to a text file. I need the cell contents to be right justified. Here is the code as it stands now:


intFH = FreeFile()

Open "Node.txt" For Output As intFH

Dim DNX As Single
Dim DNY As Single
Dim k As Integer

' Loop to print out node data - Note that Z dimesion is always zero for 2D Axisymmetric Models
For i = 1 To 9
DNX = Cells(i + 4, 10).Value
DNY = Cells(i + 4, 11).Value
Print #intFH, vbTab & i & vbTab & DNX & vbTab & DNY
Next i

For i = 1 To 43
DNX = Cells(i + 13, 10).Value
DNY = Cells(i + 13, 11).Value
k = i + 9
Print #intFH, vbTab & k & vbTab & DNX & vbTab & DNY
Next i

I need to have the counter i right justified in column 8 so that the numbers all line up with the ones digit in column 8 and the tens digit in column 7. The next number on the line is a real number in the format x.yyyyyyyyyyy up to 11 decimal places. The third number of the line will be the same way.

Typical lines need to look like this

bbbbbbb1bb8.610000000000bbbbb3.000000000000
bbbbbb10bb77.480000000000000096.00000000000

Is there a way to do this will commands that will handle the proper justifications and trailing decimal points properly?

Any help is greatly appreciated. Thank you.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,215,126
Messages
6,123,198
Members
449,090
Latest member
bes000

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