![]() |
Insert leading zero's
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 |
Insert leading zero's
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 --------------- Jacob Skaria "art" wrote: 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 |
Insert leading zero's
Here is another way to calculate intNew...
intNew = Left(intOld, (Len(intOld) - 3 + Abs(Len(intOld) - 3)) / 2) & _ Replace(Format(intOld, "!@@@"), " ", "0") -- Rick (MVP - Excel) "Jacob Skaria" wrote in message ... 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 --------------- Jacob Skaria "art" wrote: 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 |
All times are GMT +1. The time now is 09:37 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com