Questions concerning data in Textboxes (Sum / Tab / Highlight)

Maurush

New Member
Joined
Feb 9, 2011
Messages
42
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%.

rig7qu.jpg


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.
The only thing I need to know is, how can I select all the contents of a textbox by
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
Important to know is that my textboxes are on the worksheet and not on a userform,
so the code I found does not work:

Code:
    With TextBox1
        .SelStart = 0
        .SelLength = Len(.Text)
        .SetFocus
    End With
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!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Ok I found the part out with the tab:

Code:
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    With TextBox1
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
    
End Sub
So with a click on the textbox the contents are selected, but on tab it doesn't work
even tough i have EnterFieldBehaviour Selectall on.
I think it has to do with the part about numeric input, because the tab function isn't numeric.

Code:
If IsNumeric(TextBox1.Text) = False Then TextBox1.Text = ""
I also put in if text = " " then text will be 0

So how can I get this correct, how can I let the input of the textbox be numeric,
and I still can use the tab key, only to go to the next textbox??
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top