textboxes within userforms

Kmsanton

Board Regular
Joined
Jul 7, 2006
Messages
91
I created a userform and within that userform I placed a textbox. When you click on my command button the userform appears and you can type into the textbox. Is there a code that will clear the textbox everytime you open the excel document. In addition is there another code you can put in so that when you press a different command button it will clear the textbox as well.

Would they be the same code??
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You shouldn't need any code to have the textbox appear blank when the form is opened, unless you've linked it to a cell of course.

You can easily clear a textbox like this.
Code:
Private Sub CommandButton1_Click()
    TextBox1.Text = vbNullString
End Sub
 
Upvote 0
Like this?

Code:
Private Sub UserForm_Initialize()
    TextBox1.Text = ""
End Sub

Private Sub CommandButton1_Click()
    TextBox1.Text = ""
End Sub
 
Upvote 0
not working

neither of those are working. They work if I create a textbox that is not in a userform but they dont work for the textbox that is featured on my userform. My userform isn't always visible, does that matter. I've named the text box : textbox_lineal

This is the code I used

Private Sub UserForm_Initialize()
TextBox_lineal.Text = ""
End Sub

Private Sub CommandButton1_Click()
TextBox_lineal.Text = ""
End Sub


I also tried


Private Sub CommandButton1_Click()
TextBox_lineal.Text = vbNullString
End Sub




Nothing worked....any ideas
 
Upvote 0
Where is this code located?

Both Andrew and my code should only work with a textbox on a userform.

The code should be in the userform's own module.
 
Upvote 0
I put the initialize code into my textbox and that code works but I tried to put the command button code into my userform and that doesn't work. My command button is featured on my worksheet not my userform. When I press this command button I want the textbox on my userform to be blank. Where should I put the code to do this??
 
Upvote 0
Sorry I'm a little bit confused.:eek:

Why do you have the command button on the worksheet?

Why not have it on the userform?

Anyway, any code for a command button on a worksheet should go in the worksheet module of the worksheet it's on.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,949
Members
448,534
Latest member
benefuexx

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