Solved

Insert a date automatically in a Worksheet.

Posted on 2011-02-21
14
790 Views
Last Modified: 2012-05-11
I am very new at this. This function works when I run it through VBA. I want to have the date inserting in the cell below when I open the workbook. I am assuming its the Openworkbook function. But I have no clue as to how to set this up. I know I use a Macro to call it. But I prefer to automate the function. An help is appreciated.

Function DateTime()
DateTime = Now
Range("F1").Value = Now
End Function
0
Comment
Question by:pyramid
  • 4
  • 4
  • 3
  • +2
14 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 100 total points
ID: 34947416
In the ThisWorkbook module of the VBE place this code

works on F1 of first sheet

hth

Dave
Private Sub Workbook_Open()
Sheets(1).Range("F1").Value = Now
End Sub

Open in new window

0
 
LVL 6

Expert Comment

by:KnutsonBM
ID: 34947429
an easy formula is =today(), you can put that in whatever cell and today's date will show up whenever the workbook is open.

-brandon
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34947479
pyramid,

If you only want the date and not the date and time you could use this in the ThisWorkbook module.

Private Sub Workbook_Open()
Sheets(1).[F1] = Date
End Sub

Patrick
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 6

Expert Comment

by:KnutsonBM
ID: 34947969
why use vba when the formula accomplishes the same thing?  

-Brandon
0
 
LVL 3

Expert Comment

by:byronwall
ID: 34948051
You can also do

CTRL + ;

to insert the current date into the active cell.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34950052
>why use vba when the formula accomplishes the same thing?  

Because the OP specified 'automatically' in the question.
0
 
LVL 6

Expert Comment

by:KnutsonBM
ID: 34950885
putting the formula in there would be just as automatic as typing out your code. Any time you opened up the Workbook it would show today's date without any refreshing.....

just my opinion

-Brandon
0
 
LVL 1

Author Comment

by:pyramid
ID: 34952226
Hi Brettdj

I inserted the code in the My Workbook module and have attached of file image of what I did. When I saved the file and opened the workbook, the sheet did not have todays date in it. Anymore imput would be appreciated.

thank
Pyramid
Code-Image.doc
0
 
LVL 6

Expert Comment

by:KnutsonBM
ID: 34952416
have you tried putting the formula in the cell?  it is just as 'automatic' as vb code, there is no modification needed, you can put it wherever you want..........
0
 
LVL 1

Author Comment

by:pyramid
ID: 34956350
Hi KnutsonBM

I understand this but I just don't want a solution, I am looking to learn more about VBA in the Excel environment.

thanks

P.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34956484
pyramid,

>I understand this but I just don't want a solution, I am looking to learn more about VBA in the Excel environment.

If you only want the date and not the date and time you could use this in the ThisWorkbook module.

Private Sub Workbook_Open()
Sheets(1).[F1] = Date
End Sub

Patrick
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 34956693
> I inserted the code in the My Workbook module and have attached of file image of what I di

That looks right

1) Are you looking in F1 of the left most worksheet
2) Do you have a macro warning message when you open the file?

You can test the code by using F8 from the ThisWorkbook module, ie not just the open file test

Cheers
Dave
0
 
LVL 1

Author Comment

by:pyramid
ID: 34961179
Hi Dave

It will not run using F8 and when I try to run it using the run sub/userform  command button it demands that I create a macro. I eliminated all other sheets as well so that I only have Sheet 1.

thanks

P.
0
 
LVL 1

Author Comment

by:pyramid
ID: 34970869
BTW, I am running in Excel 2003. I put the code in 2007 and it works. The differences are these.
Excel 2003 environment on a IBM ThinkPad which I do not have admin rights
Excel 2007 environment on a Dell Lattitude 6400 which I have full admin rights
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

Suggested Solutions

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

803 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