write different formats into an ascii file

kato01

Board Regular
Joined
Sep 9, 2005
Messages
81
Hello,

I need to create a file from an excel sheet.
The VBA project reads values of cells and write them into the file (ofln):

Open OFLN For Output As 1
For IR = 1 To 72
XLINE =""
For IC = 11 To 19
A$ = LTrim(RTrim(Cells(IR, IC).Value))
XLINE = XLINE + Chr$(32) + A$
Next IC
XLINE = LTrim(RTrim(XLINE))
Print #1, XLINE
Next IR
Close 1

What is supposed to do, is reading in a loop (IR) a section of a row and write it on the OFLN.
The problem I have, is that some cells have the value ‘0’ (number zero) and the input file created, needs to include integers as well as real numbers.
If A2=0 (format in excel is “number”, “decimals=0”) it needs to write 0
If B2=0.0 (format in excel is “number”, “decimals=1”) it needs to write 0.0
For other values the ‘rules’ are the same:
If A2=5 (format in excel is “number”, “decimals=0”) it needs to write 5
If B2=5.0 (format in excel is “number”, “decimals=1”) it needs to write 5.0

The module, as shown above, always writes the value of the celsl in the OFLN always without decimals, which is a problem, since the code that later on reads OFLN, needs to recognize and differentiate between integers and decimals.

Any ideas?

Thanks

Katto01
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try changing Value to Text, that should return the what's in the cell(s) as it's formatted on the worksheet.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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