Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.newusers
|
|||
|
|||
![]()
I have a calendar on a user form, along with 2 textboxes. The code works
thus far. The user must click in a textbox and click a date in the calendar. I want the dates to also go to excel worksheet. Now it will if I click on each textbox with the dates a second time. How can I get the dates to go without that second click. My code is below: (NOTE: This is code I got from the community site and revised for my needs) Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() 'Gives focus to textbox on userform Set LastTextBox = Me.TextBox1 Worksheets("Part_Time_Payroll").Range("A2").Value = Format(TextBox1.Text, "mm-dd-yyyy") End Sub Private Sub TextBox2_Enter() 'Gives focus to textbox on userform Set LastTextBox = Me.TextBox2 Worksheets("Part_Time_Payroll").Range("B2").Value = Format(TextBox2.Text, "mm-dd-yyyy") End Sub Private Sub Calendar1_Click() 'If a textbox is not selected, puts message on screen to select a textbox on userform If LastTextBox Is Nothing Then MsgBox "Select a textbox first!" Exit Sub Else 'If a textbox is selected, puts date chosen in the selected textbox on userform LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") End If End Sub Private Sub cmdClose_Click() Unload Me End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Set Textbox on a Form to Deafault | New Users to Excel | |||
Text Size in Label or Textbox in Form | Excel Discussion (Misc queries) | |||
Textbox added to Form at runtime too small, can't control size andchange event won't trigger | Excel Worksheet Functions | |||
end down option in a textbox of a form | Excel Discussion (Misc queries) | |||
User Form in VB = TextBox | Excel Discussion (Misc queries) |