A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

pass to textbox on a form and to excel worksheet



 
 
Thread Tools Display Modes
  #1  
Old March 16th, 2010, 07:35 PM posted to microsoft.public.excel.newusers
Cvw
external usenet poster
 
Posts: 3
Default pass to textbox on a form and to excel worksheet

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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:29 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.