Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
klafert
 
Posts: n/a
Default Help with leading zero getting strip by Excel when saving to a .cs

I am saving a worksheet from Excel to .csv I have a number 0000457, but when
I open it up the .csv file then the zeros all goine. I can show them in
Excel if I format the column as text. Need answer ASAP!!
  #2   Report Post  
Mexage
 
Posts: n/a
Default

Type a ' before the number.

Hope this helps; if it does, please rate my post.

G.Morales.

"klafert" wrote:

I am saving a worksheet from Excel to .csv I have a number 0000457, but when
I open it up the .csv file then the zeros all goine. I can show them in
Excel if I format the column as text. Need answer ASAP!!

  #3   Report Post  
Peo Sjoblom
 
Posts: n/a
Default

It gets stripped when opening it in excel, not when saving as CSV, you can
change it to a txt file and use the text import wizard and import it as text
or if the number of digits are equal use a custom format like 0000000

Regards,

Peo Sjoblom

"klafert" wrote:

I am saving a worksheet from Excel to .csv I have a number 0000457, but when
I open it up the .csv file then the zeros all goine. I can show them in
Excel if I format the column as text. Need answer ASAP!!

  #4   Report Post  
klafert
 
Posts: n/a
Default

That only works when the Spreadsheet is the the .xls format and not the .csv
format.

"Mexage" wrote:

Type a ' before the number.

Hope this helps; if it does, please rate my post.

G.Morales.

"klafert" wrote:

I am saving a worksheet from Excel to .csv I have a number 0000457, but when
I open it up the .csv file then the zeros all goine. I can show them in
Excel if I format the column as text. Need answer ASAP!!

  #5   Report Post  
ras
 
Posts: n/a
Default

When I prefix a number in a CSV with a single quote, the single quote appears
in the cell. If I then select the cell, put my cursor in the edit bar and
hit tab, it'll reinterpret the quote and treat the cell as text.

Is there any way to write a macro that visits each cell and does this? (No,
recording this into a macro does no good.)

This seems to be a common problem- and no, treating it as a txt file and
specifying all the formats is not a decent solution. I could write a perl
script to do this (or presumably a Basic script), but that seems like a lot
of work for a simple problem.


  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

I created a .csv file that looked like this:

'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345

And this worked ok:

Option Explicit
Sub testme02()

Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myRng = Nothing
On Error Resume Next
Set myRng = .Cells.SpecialCells(xlCellTypeConstants, xlTextValues)
On Error GoTo 0
End With

If myRng Is Nothing Then
MsgBox "No text values found"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
If Left(.Value, 1) = "'" Then
.NumberFormat = "@"
.Value = Mid(.Value, 2)
End If
End With
Next myCell

End Sub


I created a .csv file that looked like this:

'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345
'1234,'1234,'2345,'2345



ras wrote:

When I prefix a number in a CSV with a single quote, the single quote appears
in the cell. If I then select the cell, put my cursor in the edit bar and
hit tab, it'll reinterpret the quote and treat the cell as text.

Is there any way to write a macro that visits each cell and does this? (No,
recording this into a macro does no good.)

This seems to be a common problem- and no, treating it as a txt file and
specifying all the formats is not a decent solution. I could write a perl
script to do this (or presumably a Basic script), but that seems like a lot
of work for a simple problem.


--

Dave Peterson
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
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
how to convert GETPIVOTDATA from excel 2000 to excel 2002... Need_help_on_excel Excel Worksheet Functions 1 March 15th 05 01:08 AM
Difference in number of Excel NewsGroups Hari Prasadh Excel Discussion (Misc queries) 1 January 25th 05 11:32 AM
Excel should add numbers without leading punctuation Transplanted Buckeye Excel Discussion (Misc queries) 6 January 13th 05 06:07 AM
numbers and text in Excel to read as text keeping the leading zer. Ralph Excel Discussion (Misc queries) 2 December 10th 04 07:05 PM


All times are GMT +1. The time now is 08:49 AM.

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

About Us

"It's about Microsoft Excel"