how to close a userform with a commandbutton

  • Thread starter Thread starter Dave Potter
  • Start date Start date
D

Dave Potter

I have a userform1 which contains a label, a textbox and a
commandbutton. I would like to show the userform1 when the workbook
opens and have the user enter the date in the textbox and have the
date in the textbox returned to a cell in some worksheet (doesnt
matter what name the ws is) when the user clicks the commandbutton.
I also need to know how to close the userform1 when the user clicks
the commandbutton.

using xl2002 in winXP pro

TIA
Dave
 
1.. Open the workbook that you want this user input for.
2.. Press Alt-F11 to start the VBA editor.
3.. On the left part of the screen under 'Project -VBAProject" look for
VBAProject(WorkBook Name) where the name of your workbook is in parenthesis.
4.. Click the last item on that tree, "ThisWorkBook".
5.. Above the right part of the screen are two drop-down lists. Click the
left on and select Workbook.
6.. You will see Private Sub Workbook_Open() followed by a blank line and
End Sub.
7.. In the blank area, type
Range("A1") = InputBox("Enter the Date", "Date")



No userform needed.



Otherwise, you can insert UserForm1.Show in the blank line. Then in the
userform code (double click the command button while in VBA editor) type:



Private Sub CommandButton1_Click()

Range("A1") = TextBox1

Unload Me

End Sub





You will need to substitute the cell you want for A1.
 
Back
Top