CheekyDevil2386
New Member
- Joined
- Oct 19, 2020
- Messages
- 6
- Office Version
- 2013
- Platform
- Windows
Hi all,
Having an issue with the below code. It works fine except with numbers starting with less than 12 for some reason.
For context, it is meant to change a string of numbers entered in a UserForm Textbox into "account format" eg, 123456789012300 would become 012-3456-7890123-00 (I have it set to enter the leading "0" automatically as that is how our system formats account numbers)
Any number greater than 1 to begin with works fine, but when entering a number such as 123224 for example will change the number in the textbox to something random (I entered "123456" and it changed to "56-8654--")
Really can't understand why it is changing the digits entered, and only for those beginning with 1.
Any assistance would be greatly appreciated.
Having an issue with the below code. It works fine except with numbers starting with less than 12 for some reason.
For context, it is meant to change a string of numbers entered in a UserForm Textbox into "account format" eg, 123456789012300 would become 012-3456-7890123-00 (I have it set to enter the leading "0" automatically as that is how our system formats account numbers)
Any number greater than 1 to begin with works fine, but when entering a number such as 123224 for example will change the number in the textbox to something random (I entered "123456" and it changed to "56-8654--")
Really can't understand why it is changing the digits entered, and only for those beginning with 1.
Any assistance would be greatly appreciated.
VBA Code:
Private Sub TextBox4_Change()
Dim Account As String
Dim Length As Integer
Account = TextBox4.Text
Length = Len(Account)
Select Case Length
Case 2
TextBox4.Text = Format(TextBox4, "0##") & "-"
Case 8
TextBox4.Text = Format(TextBox4, "##-####") & "-"
Case 16
TextBox4.Text = Format(TextBox4, "##-####-####") & "-"
End Select
ActiveSheet.Range("B2").Value = TextBox4.Value
End Sub