In my UserForm, I want to set a default value for my TextBox, that will highlight when focused upon.
Private Sub UserForm_Initialize() NameTextBox.Value = "Your Name Here" NameTextBox.SetFocus End Sub
When this code runs, the cursor should set at the end of the default text, i.e. after “…Here”. I want “Your Name Here” to be highlighted so that when the form is generated, the user can start replacing that default/placeholder text.
Can you help me write the code to set default values that are editable?
This will select all the text in the TextBox:
Private Sub UserForm_Initialize() With Me.NameTextBox .Value = "Your Name Here" .SetFocus .SelStart = 0 .SelLength = Len(.Text) End With End Sub
EnterFieldBehavior property to
frmEnterFieldBehaviorSelectAll so that when the focus goes to that field, the whole field is selected.
how about this line of code when your form loads?