How to autoincrement with Leading Zeroes?

  • Thread starter Thread starter vrk1
  • Start date Start date
V

vrk1

I have a string variable: x = "item000"

I would like to code to autogenerate a code such that when the code gets
executed, I increment the item by 1 from its previous value. (so, I see
values like item000, item001, item 002....item010, item 011...)
How do I accomplish this?

The code I have thus far which doesn't work is below:

rightstring = Right(x,3)
lefstring = left(x,len(x)-len(rightstring))
autonum = cstr(Right("000" & cint(rightstring) + 1, 3))
msgbox(autonum)
__________________________________________

Any ideas how to get this done?
 
Try . Use Format function

strAutoNum = "item002"
strAutoNum = "item" & Format(Right(strAutoNum, 3) + 1, "000")
MsgBox strAutoNum

If this post helps click Yes
 
This solved my problem. Thanks

Jacob Skaria said:
Try . Use Format function

strAutoNum = "item002"
strAutoNum = "item" & Format(Right(strAutoNum, 3) + 1, "000")
MsgBox strAutoNum

If this post helps click Yes
 
Back
Top