Adding a Leter to a Numerical Value on Exit
Leith,
Absolutely beautiful.
Thanks
Corey....
"Leith Ross" wrote in message
...
On Jul 6, 6:54 pm, "Corey ...." wrote:
Private Sub TextBox1_Change()
TextBox1.MaxLength = "4"
If IsNumeric(TextBox1) = True Then TextBox1 = UCase(TextBox1) Else
TextBox1
= ""
End Sub
The above code i am using to ensure only a 4 digit numerical value is
placed
in the textbox.
I actually want on EXIT only that value entered, but with a "A" before
it.
Like A4587 etc.
I tried using :
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.MaxLength="5"
Textbox1.value = "A"+Textbox1.value
End Sub
But it clears the Textbox value
Is there a way around this?
Hello Corey,
This TextBox_Exit event code will add the "A" if the value is a number
and is equal to 4 characters in length. Otherwise, the entry is
cleared and the cursor is placed back at the beginning of the TextBox.
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim TextVal As Variant
TextVal = TextBox1.Value
With TextBox1
If Len(.Value) = 4 And IsNumeric(TextVal) Then
.Value = "A" & .Value
Else
.Value = ""
Cancel = True
End If
End With
End Sub
Sincerely,
Leith Ross
|