Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default leading zeros

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default leading zeros


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default leading zeros

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Leading Zeros Erika Excel Discussion (Misc queries) 4 March 27th 09 04:55 PM
Leading Zeros JSpence2003 Excel Discussion (Misc queries) 2 November 14th 07 09:28 PM
Leading Zeros Ben Watts Excel Worksheet Functions 8 September 26th 07 05:44 PM
Leading zeros LeePotts Excel Discussion (Misc queries) 2 August 17th 05 02:46 PM
save text field w/ leading zeros in .csv format & not lose zeros? Ques Excel Discussion (Misc queries) 1 May 4th 05 06:21 PM


All times are GMT +1. The time now is 11:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"