Solved

VBA for Excel 2010

Posted on 2014-02-17
3
539 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 45

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now