Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel User form Help needed 2

Status
Not open for further replies.

kitackers

MIS
Apr 16, 2004
33
GB
I'm reasonably new to VBA in excel and need some help on a spreadheet with a calender control function.

I have a calender control on a spreadsheet that opens up with a button, when the date is selected it populates cell D8 with the date, but I then have to click the "X" to close the calender. I want to know if I can get the form to close at the same time.

At the moment the code on the form is

Private Sub Calendar1_Click()
Range("D8") = Calendar1.Value
ActiveCell.NumberFormat = "dd/mm/yy"
End Sub

I've trawled through the FAQ's but can't find anything.

Can anyone help?!?
 
Unload userform:
Private Sub Calendar1_Click()
Range("D8") = Calendar1.Value
ActiveCell.NumberFormat = "dd/mm/yy"
Unload Me
End Sub

With your code you set value of D8, and format active cell. In general, they can be different.
 
Assuming the calendar control is in UserForm1:

Code:
Private Sub Calendar1_Click()
    Range("D8") = Calendar1.Value
    ActiveCell.NumberFormat = "dd/mm/yy"
    Unload UserForm1
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top