Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting rid of zeros from the beginning of numbers

Status
Not open for further replies.

03021979

Vendor
Feb 23, 2006
35
PL
I have to get rid of all zeros from the beginning of numbers, i.e. if the number is 0005678, I have to have 5678 as a result. The number of zeros may change. Is there any chance to make VB do this?
 
Have a look at the Val function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
and if we have a text string 00HHHH, how to get rid of zeros in this case?
 
You may create your own function:
Public Function LTrimZero(myVar) As String
Dim s As String
s = myVar & ""
While Left(s, 1) = "0"
s = Mid(s, 2)
Wend
LTrimZero = s
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
There is always more than one way to trim a cat.

Do While Left(mystring, 1) = "0"
mystring = Application.WorksheetFunction.Replace(mystring, 1, 1, "")
Loop
 
GVF, what happens with your solution if the A of VBA isn't excel ?
 
A simple CDBL("0005678") will do the trick if you always have numbers and this will work in any office application.
 
Ooops,

Sorry PHV. I made an assumption. We know what that means.

Greg
 
Greg, sure ;-)
Stuck, reread the post time stamped 23 Feb 06 4:38

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH,

I think Mr. 03021979 has three zeros in front of his H's in that post.
If you're in Excel, my snippet still works (that's a zero in the quotes in my snippet). But maybe...

Do While Left(mystring, 1) = "0" 'zero
mystring = Right(mystring, Len(mystring) - 1)
Loop

Or
While InStr(1, mystring, "0") = 1
mystring = Right(mystring, Len(mystring) - 1)
Wend

either would be more generic.
I notice that the original question is from Mr. 03021979
then

OurQuestioner = "03021979"
Do While Left(OurQuestioner, 1) = "0" 'zero
mystring = Right(OurQuestioner, Len(OurQuestioner) - 1)
Loop

Mr. 03021979 probably uses 3021979 as a nickname. His surname appears to be "vendor" which doesn't need to be trimmed.
Of course I'm assuming that our questioner is male. Isn't an assumption what got me in trouble in the first place?

Greg

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top