Insert leading zero's

A

art

Hello:

I would like to use a code that will do the following:

If I enter in Range(ABC...) 1 or 2 digits, then it should be followed with
two zero's, and if its more than 2 digits then leave it as is. So if I enter
4, it should turn it to 400 and if I enter 435 it should leave it like that.

Thanks so Much.

Art
 
J

Jacob Skaria

Somthing like the below

Dim intOld as Integer, intNew As Integer

intOld = 43
intNew = IIf(intOld < 100, intOld * 10 ^ (3 - Len(intOld)), intOld)

If this post helps click Yes
 
R

Rick Rothstein

Here is another way to calculate intNew...

intNew = Left(intOld, (Len(intOld) - 3 + Abs(Len(intOld) - 3)) / 2) & _
Replace(Format(intOld, "!@@@"), " ", "0")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top