Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When export to Excel most of the time I loose the leading zeros, I want to
know if someone have a macro to restore the zeros? Thanks, |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Fernando Duran wrote: When export to Excel most of the time I loose the leading zeros, I want to know if someone have a macro to restore the zeros? Thanks, You should watch how the data is being imported to avoid in the future. However, This should work to bring it back once you already have it imported. Sub LeadZeros() Dim DLength As Integer Dim xlCurrLen As Integer DLength = 10 'Desired total length Dim xlCell As Range For Each xlCell In ActiveSheet.UsedRange xlCurrLen = Len(Trim(xlCell.Value)) If xlCurrLen < DLength And xlCurrLen < 0 Then 'Have to prepend value with tick to retain the zeros xlCell.Value = "'" & String(DLength - xlCurrLen, "0") & xlCell.Value End If Next xlCell End Sub The weakness I see is that i's converted to text. So you will have to deal with that if calcing the data. Not sure how to lead zeros and not have it as text. I'll be watching this post to see if one of the gurus post a better suggestion. Regards, Jamie |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
http://www.asap-utilities.com/
Try this awesome add in. Ensure the folder is placed in the root of the C drive when installing. It will add an extra button with a huge folder of items -- Saruman --------------------------------------------------------------------------- All Outgoing Mail Scanned By Norton Antivirus 2003 --------------------------------------------------------------------------- "jseven" wrote in message ups.com... Fernando Duran wrote: When export to Excel most of the time I loose the leading zeros, I want to know if someone have a macro to restore the zeros? Thanks, You should watch how the data is being imported to avoid in the future. However, This should work to bring it back once you already have it imported. Sub LeadZeros() Dim DLength As Integer Dim xlCurrLen As Integer DLength = 10 'Desired total length Dim xlCell As Range For Each xlCell In ActiveSheet.UsedRange xlCurrLen = Len(Trim(xlCell.Value)) If xlCurrLen < DLength And xlCurrLen < 0 Then 'Have to prepend value with tick to retain the zeros xlCell.Value = "'" & String(DLength - xlCurrLen, "0") & xlCell.Value End If Next xlCell End Sub The weakness I see is that i's converted to text. So you will have to deal with that if calcing the data. Not sure how to lead zeros and not have it as text. I'll be watching this post to see if one of the gurus post a better suggestion. Regards, Jamie |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Add Leading Zeros | Excel Discussion (Misc queries) | |||
Leading Zeros | Excel Discussion (Misc queries) | |||
Leading Zeros | Excel Worksheet Functions | |||
Leading zeros | Excel Discussion (Misc queries) | |||
save text field w/ leading zeros in .csv format & not lose zeros? | Excel Discussion (Misc queries) |