write different formats into an ascii file

kato01

Board Regular
Joined
Sep 9, 2005
Messages
56
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
Try changing Value to Text, that should return the what's in the cell(s) as it's formatted on the worksheet.
 

Forum statistics

Threads
1,082,151
Messages
5,363,430
Members
400,736
Latest member
Aida

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top