Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 563
- Office Version
- 365
- 2010
- Platform
- Windows
When my userform initializes, I am using the following format in the form's caption P4-2021-##. This starts in range "A6". However, when this form is first created Range("A6") is empty and therefore should start with "P4-2021-01". When a value is entered in Range("A7") the ## should increment by one, so it would be "P4-2021-02" and so on. How can I have the code look at the last two numbers of the previous cell and add one to the last two digits using vba. Like this, but this is wrong.
How do I force a leading zero until the number reaches 10?
Thank you
VBA Code:
Private Sub UserForm_Initialize()
Dim Numbers As String
Numbers = "01"
MsgBox CLng(Format(Numbers, "##"))
Me.Caption = ("P4" & "-" & Format(Now(), "yyyy")) & "-" & Format(Numbers, "##")
End Sub
Thank you