Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default droping leading zeros when writing to a file

My problem is that VBA is writing the numbers to a file PATH but it
drops the leading zeros. I already tried to make them strings but if I
do that then it adds parenthesis to the "string" which I dont want. I
dont understand why it is not writing EXACTLY what I am telling it to
output to file. Please help, thanks.

Colin Marker

Code -

intFile = FreeFile
Open PATH For Append As #intFile
colIndex = 1
rwIndex = 1

Do Until Cells(rwIndex, colIndex) = ""
Write #intFile, 0.53, 5.24, 0.15, -0.58, -0.862
rwIndex = rwIndex + 1
Loop
Close #intFile

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default droping leading zeros when writing to a file

Hi Colin,

Use Print rather than Write. This will work as you wish:

Print #intFile, 0.53, 5.24, 0.15, -0.58, -0.862

In addition, I assume you're taking this data from your worksheet. Don't
forget you can always use Format to easily modify the format of the
numbers.

rwIndex = 1
colIndex = 1
Do Until Cells(rwIndex, colIndex) = ""
Do Until Cells(rwIndex, colIndex) = ""
Print #intFile, Format(Cells(rwIndex, colIndex),"00.00#")
colIndex = colIndex + 1
Loop
colIndex = 1
rwIndex = rwIndex + 1
Loop

HTH,
Gareth

wrote:
My problem is that VBA is writing the numbers to a file PATH but it
drops the leading zeros. I already tried to make them strings but if I
do that then it adds parenthesis to the "string" which I dont want. I
dont understand why it is not writing EXACTLY what I am telling it to
output to file. Please help, thanks.

Colin Marker

Code -

intFile = FreeFile
Open PATH For Append As #intFile
colIndex = 1
rwIndex = 1

Do Until Cells(rwIndex, colIndex) = ""
Write #intFile, 0.53, 5.24, 0.15, -0.58, -0.862
rwIndex = rwIndex + 1
Loop
Close #intFile

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Leading zeros won't convert to csv file in Excel ver 6 SP2 Pedro Excel Discussion (Misc queries) 2 September 2nd 06 01:30 AM
How do i save a csv file to keep leading zeros please? kingie Excel Discussion (Misc queries) 4 August 8th 06 09:31 PM
How do I open a csv file and not have leading zeros eliminated AS400_EXCEL_John_B Excel Discussion (Misc queries) 2 July 25th 06 07:27 PM
Loosing Leading zeros in CSV file Joe Excel Discussion (Misc queries) 2 January 3rd 06 12:12 PM
CSV File - Leading Zeros Floridagal Excel Discussion (Misc queries) 2 August 6th 05 12:34 AM


All times are GMT +1. The time now is 09:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"