Vba textbox control text box in Excel

The Textbox control is used to get input from the user.

The textbox control can be used to get alphabets,numerics and other symbols.

There will hardly be a form without a textbox control.

This is a basic control and a must needed for obtaining user input.

Like other controls textbox also has various properties as explained in the previous chapters.

Some of the distinct properties are discussed below

1.PasswordChar property

This property is used to set the password character of the textbox, when used to obtain password from the user.

2.Multiline property

This property specifies whether the textbox can get multiline input.

This takes a binary value,true or false.

Text Property

This property is used to get or set the text in the textbox control.

Events of Textbox control

The events associated with textbox controls are as discussed below:

1.Change event:

This event is triggered whenever the text in the textbox changes.

The following code illustrates this

  1. Private Sub TextBox1_Change()
  2. MsgBox "Changed"
  3. End Sub

2.KeyDown Event

This event is triggered whenever a text is entered in the textbox.

This event is triggered the moment a key is pressed.

For example, the following snippet checks the text input and triggers an action whenever key "a" is pressed.

  1. Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  2. If KeyCode = vbKeyA Then
  3. MsgBox "You Pressed A"
  4. End If
  5. End Sub

3.KeyUp Event

This event is same as the Keydown, except that, this event is triggered at the moment of key release.

The follwing code illustrates this; with the same logic as above.

  1. Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  2. If KeyCode = vbKeyA Then
  3. MsgBox "You Pressed A"
  4. End If
  5. End Sub

excel vba textbox control text box

excel vba textbox control text box

excel vba textbox control text box

 

You can find similar Excel Questions and Answer hereunder

1) How can I get the most frequently occurring text in a range?

2) Line break in vba message box in Excel

3) Here an explanation about frames and how to control frames in Excel VBA

4) Here an explanation about list box and how to control list boxes in Excel VBA

5) Remove the apostrophe cell text values in Excel

6) How to display messages boxes in VBA with the msgbox function

7) How can I have text autocomplete based on values previously entered in Column?

8) Here an explanation about label controls in the various forms and controls using VBA

9) Converting numbers stored as text to numbers via macro in Excel

10) Can I add a Text histogram to Table data to make it visually appealing and easy to interpret?

 

Here the previous and next chapter