?
Solved

VBA for Excel 2010

Posted on 2014-02-17
3
Medium Priority
?
567 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 50

Expert Comment

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

Accepted Solution

by:
gowflow earned 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

840 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