Solved

VBA for Excel 2010

Posted on 2014-02-17
3
544 Views
Last Modified: 2014-02-17
I have a VBA UserForm within Excel 2010 and on it is a Date text box.  I want the Text Box to perfill with Today's date when the UserForm is called.  What is the code to make this happen?   Is there another control I should be using.  The value prefilled or entered by my user in the TextBox will be placed into the Excel worksheet.
0
Comment
Question by:cowboywm
3 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39865346
TextBox1.Text = Format(Now(), "short date")
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39865426
for the first part MartinLiss gave you the solution

and for
 The value prefilled or entered by my user in the TextBox will be placed into the Excel worksheet.

then you put in ControlSource property of the textbox
TextBox1.ControlSource = "Sheet1!A1"
'Place the result of the textbox into sheet1 of cell A1

gowflow
0
 

Author Closing Comment

by:cowboywm
ID: 39866234
Thank you all for your input.  This is the final code.

Private Sub UserForm_Initialize()
    DateTextBox.Text = Format(Now(), "short date")
End Sub

I also have a macro that dumps the data to the correct spot on the spreadsheet once the command button is clicked.  Here is the portion dealing with the date data.

Private Sub StopCommandButton_Click()
    ActiveCell.Offset(0, -8).Range("A1").Activate   'Moves to Date Field(cell)
    MyAnswer = DateTextBox.Text
    ActiveCell.FormulaR1C1 = MyAnswer
End Sub
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As freelancing is becoming more and more common in the tech industry, certain obstacles are proving to be a challenge to those who are used to more traditional, structured employment. This article is meant to help identify such obstacles and offer a…
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question