Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel strips out the zero padding

Status
Not open for further replies.

dpdg

Programmer
Joined
May 23, 2005
Messages
148
Location
US
I've got a module in my app that downloads data to an Excel Spreadsheet. I all works very well except for 2 columns that have numbers that are padded with zeros to the left. I don't know why it's that way it's just the way I get the numbers and store them in my database.

What happens is that when they are downloaded to Excel, the zeros are stripped out and only the (non-zero) numbers are left. The only way that I've found to keep the zeros at the front is to put double quotes on either side of the zero-padded numbers.

Is there a way to format the cells or something as it is downloading so that excel doesn't go and automatically strip the zeros? Is there a better way to do this?
 
The only other way I can think of is somehow format the cell to a text cell. But I have no idea how do to that in code.

jim
 
I tried this in my code:

objSheet.Cell(r, c) = "=TEXT(" & CStr(myVariable) & ", 0)"

It stored the number as text, but still stripped out the zeros first.

Excel can be a real pain to work with sometimes... it has a mind of its own.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top