View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Leading zeros in Excel

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



omsoft wrote:

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.


--

Dave Peterson