View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mike Fogleman Mike Fogleman is offline
external usenet poster
 
Posts: 1,092
Default Preserving leading zero

You didn't mention how you got rid of the "-", but this seems to work for
me:

I have this in cell A1: 010-056

Sub test()
Dim x As String

x = Range("A1").Value
x = Replace(x, "-", "", , , vbTextCompare)
End Sub

Mike F
"a" wrote in message
link.net...
Hello,

I'm certain that there should be a way to preserve a leading zero when you
don't know the length of the string - but I certainly don't know how.

I have a string like "010-056". If I put the variable in a watch window -
it comes up as a string. The problem is that I need to get rid of the
"-". When I do this, the string becomes a number.

Because the left character is not always a zero and, as I mentioned, the
length of the string varies, I cannot figure out how to keep the leading
zero intact when I replace the "-".

Does anybody have a solution to this?

Any help in this would be most appreciated.

Thanks much in advance.

Anita