View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
pbrase pbrase is offline
external usenet poster
 
Posts: 3
Default How to preserve leading zeroes

Laurin:
Thank you very much. I will give it a try. Does this not seem like an
awful lot of trouble, though, to fix something that should be quite simple?
When you are in the spreadsheet, you can just go to Format Cells, select
Text, and then type in all the leading 0s you want. I'm rather astounded
that something I can do so easily in the interface seems programmatically to
require a detour through Siberia.
Peter
"Laurin" wrote:


If the numbers all have the same length, you can try the following which
works on one cell. With a minor bit of modification you can make it
work on all of the returned data using a loop.

Range("A1").Select
Selection.NumberFormat = "@"
Dim I As Variant
I = Range("A1").Value
Select Case Len(I)
Case Is = 1: I = "00000" & I
Case Is = 2: I = "0000" & I
Case Is = 3: I = "000" & I
Case Is = 4: I = "00" & I
Case Is = 5: I = "0" & I
Case Else: I = I
End Select
Range("A1") = I


--
Laurin
------------------------------------------------------------------------
Laurin's Profile: http://www.excelforum.com/member.php...o&userid=26832
View this thread: http://www.excelforum.com/showthread...hreadid=491854