Leading zeros in Excel

O

omsoft

I have Excel 2007 worksheet. Besides other data, it contains productnumbers
(10 digits). Some of this product # begin with 0. The sheet is formatted as
General.

This sheet is used as an input into another app which can not take text as
format.

Does anyone know how do I format product # so that leading zeros are
preserved? I tried it as "@" and "0000000000" and in Excel it looks like
there is a leading zero, it is just formatting and gets dropped in the other
app.

How do I do this? I am creating this worksheet using VBA.

Thanks much.
 
D

Dave Peterson

If you use a numberformat of Text (or "@" in code), then whatever you plop into
that cell will be kept. If you want leading 0's, you'll have to put them there
yourself.

Dim myNum As Long
myNum = 1234
With ActiveCell
.NumberFormat = "@"
.Value = Right(Format(myNum, String(10, "0")), 10)
End With
 
O

omsoft

Thanks Dave, the leading zeros are there and I see them. But may be it is the
other system's fault in reading it. But I have to go around it.

In any case, I will try the code that you have below. Thanks for the same.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top