Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding a Leter to a Numerical Value on Exit
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding a Leter to a Numerical Value on Exit
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding a Leter to a Numerical Value on Exit
Just realised, if i enter the 4 digit number then exit, all is good.
But if i need to change the number, i am unable to enter the textbox again ? "Corey ...." wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Count occurance of a leter in a text string | Excel Worksheet Functions | |||
Giving letters a numerical value, then adding the total. | Excel Discussion (Misc queries) | |||
Adding up non numerical values | New Users to Excel | |||
Adding numerical values based on multiple values in another column | Excel Worksheet Functions | |||
Adding numbers to an incomplete numerical list | Excel Discussion (Misc queries) |