Hello guys,
didn't know how to set up the thread name, but i have the following which I cannot figure out.
I have 6 textboxes in which I only allow numeric data. Textbox6 contains the sum of textboxes 1 to 5,
which is a maximum of 100%.
If I want the value of textbox6 to be working I will need to have a number in all textboxes,
so I want to start all textboxes with the number 0.
The following things I figured out (maybe you got better solutions?)
clicking in it, and overwrite everything. Because if I click now the 0 still is standing and
everything else is getting written behind.
I have the following code:
Important to know is that my textboxes are on the worksheet and not on a userform,
so the code I found does not work:
Maybe a nicer solution is that people can divide the 100% over the textboxes.
So if i did put in 20 in the first 4 textboxes, textbox 5 automatically is set to 20% so
it will make a total of 100%.
Or if you put in 20 in the first textbox you still have 80% to divide, if you put in 80 in the
2nd textbox, all the other textboxes are filled in with 0.
I appreciate your help with this!
didn't know how to set up the thread name, but i have the following which I cannot figure out.
I have 6 textboxes in which I only allow numeric data. Textbox6 contains the sum of textboxes 1 to 5,
which is a maximum of 100%.
If I want the value of textbox6 to be working I will need to have a number in all textboxes,
so I want to start all textboxes with the number 0.
The following things I figured out (maybe you got better solutions?)
- Always start with the number 0;
- Only possible to add numbers, no other characters;
- Only possible to type a maximum of 3 characters in each textbox;
- Go to another textbox with tab;
- Total sum of textboxes 1 to 5 in textbox 6.
clicking in it, and overwrite everything. Because if I click now the 0 still is standing and
everything else is getting written behind.
I have the following code:
Code:
Private Sub TextBox1_Change()
If IsNumeric(TextBox1.Text) = False Then TextBox1.Text = ""
'// if text isnt numbers then it wont get displayed.
If Val(TextBox1.Text) > 100 Then
MsgBox "exceeded maximum value"
TextBox1.Text = "0"
End If
EnteredText = TextBox1.Value
NumberOfCharacters = Len(EnteredText)
If Right(EnteredText, 1) = Chr(9) Then
TextBox1.Value = Left(EnteredText, NumberOfCharacters - 1)
TextBox2.Activate
End If
TextBox1.MaxLength = 3
If TextBox1.Value = "" Then TextBox1.Value = ""
If TextBox2.Value = "" Then TextBox2.Value = ""
If TextBox3.Value = "" Then TextBox3.Value = ""
If TextBox4.Value = "" Then TextBox4.Value = ""
If TextBox5.Value = "" Then TextBox5.Value = ""
TextBox6.Value = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value)
End Sub
so the code I found does not work:
Code:
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
So if i did put in 20 in the first 4 textboxes, textbox 5 automatically is set to 20% so
it will make a total of 100%.
Or if you put in 20 in the first textbox you still have 80% to divide, if you put in 80 in the
2nd textbox, all the other textboxes are filled in with 0.
I appreciate your help with this!