Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count occurance of a leter in a text string justaman Excel Worksheet Functions 3 October 11th 08 04:51 AM
Giving letters a numerical value, then adding the total. Richard in Stockholm Excel Discussion (Misc queries) 17 April 9th 08 05:01 PM
Adding up non numerical values Wooster New Users to Excel 3 September 23rd 07 01:03 AM
Adding numerical values based on multiple values in another column Kazmaniac Excel Worksheet Functions 6 April 4th 07 08:53 PM
Adding numbers to an incomplete numerical list hana Excel Discussion (Misc queries) 17 January 11th 07 09:46 PM


All times are GMT +1. The time now is 01:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"