ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   LeadingZeros\CSV (https://www.excelbanter.com/excel-programming/336846-leadingzeros%5Ccsv.html)

gh

LeadingZeros\CSV
 
I have a text file I open up in excel. One of the columns has numbers
with leading zeros. I change the format to text and I save it as a csv
file. Then when I import the file into another program the zeros are
gone. I also have some numbers like(65110231147009) and when I import
the file into another program, they end up like (6.51E+13) which turns
the number into (65100000000000). I also reopened the spreadsheet after
saving it and they are not correct. Is this because I am saving the
spreadsheet as a csv? If so how can I keep the data correct? I have to
use csv or xml to import the data into another program. I am using
excel 97.

TIA

Jean-Yves[_2_]

LeadingZeros\CSV
 
Hi,

Create your CSV file using the old method

Sub CreateCSV()
Dim strLine As String
Dim FileNum As Integer
Dim cl As Range
Dim i As Byte
FileNum = FreeFile
Open "C:\Yourpath\MyCsvFile.csv" For Output As #FileNum

For Each cl In Range("A1", Range("A1").End(xlDown))
i = 1
strLine = cl.Value
Do While IsEmpty(cl.Offset(, i)) = False
strLine = strLine & ", " & cl.Offset(, i) 'format your cell value here
as applicable
i = i + 1
Loop
Print #FileNum, strLine
Next cl
Close #FileNum
MsgBox "C:\Yourpath\MyCsvFile.csv created !", vbInformation, "Export done"
End Sub

Regards
Jean-Yves

"gh" wrote in message
...
I have a text file I open up in excel. One of the columns has numbers
with leading zeros. I change the format to text and I save it as a csv
file. Then when I import the file into another program the zeros are
gone. I also have some numbers like(65110231147009) and when I import
the file into another program, they end up like (6.51E+13) which turns
the number into (65100000000000). I also reopened the spreadsheet after
saving it and they are not correct. Is this because I am saving the
spreadsheet as a csv? If so how can I keep the data correct? I have to
use csv or xml to import the data into another program. I am using
excel 97.

TIA





All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com