Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Leading zeros in Excel
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Leading zeros in Excel
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. "Dave Peterson" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel Leading Zeros | Excel Discussion (Misc queries) | |||
Importing to Excel from csv AND keep leading zeros | Excel Discussion (Misc queries) | |||
Excel Leading Zeros | Excel Discussion (Misc queries) | |||
leading zeros in excel | Excel Discussion (Misc queries) | |||
save text field w/ leading zeros in .csv format & not lose zeros? | Excel Discussion (Misc queries) |