Solved

VBA for Excel 2010

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tags from access to excel 3 24
Delete texts with font color 16 29
Searching good PDF to OCR 7 28
Help with Excel formula 6 31
Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
Companies keep a much closer eye on costs today, so changing to new Technology – Microsoft Office 365 is the smartest move to take.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

947 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

18 Experts available now in Live!

Get 1:1 Help Now