Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 29
Default Date Function needed

I'm running into a problem with putting a date in a form i'm making.
I want to have todays date populate a cell when the form is opened.
But only once. So if a person opens the form for the first time it
populates todays date... today(). But if they open the form up again
that date will not change. If you use =today() then each time you
open the form up it populates that cell with today’s date.

Any idea's how i can code a cell with today’s date upon creation but
not have it change each time the form is opened.

Thanks for the help,
Steve
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Date Function needed

Hi Steve:

This little Workbook event macro runs whenever the workbook is opened.

If Sheet1 cell A1 is empty, the date is inserted.
If Sheet1 cell A1 is not empty, no insertion is made.

So if the workbook is opened, saved, and re-opened, the first date is not
over-written:

Private Sub Workbook_Open()
With Sheets("Sheet1").Range("A1")
If .Value = "" Then
.Value = Date
End If
End With
End Sub

Because it is workbook code, it is very easy to install and use:

1. right-click the tiny Excel icon just to the left of File on the Menu Bar
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200795


"smonczka" wrote:

I'm running into a problem with putting a date in a form i'm making.
I want to have todays date populate a cell when the form is opened.
But only once. So if a person opens the form for the first time it
populates todays date... today(). But if they open the form up again
that date will not change. If you use =today() then each time you
open the form up it populates that cell with todays date.

Any idea's how i can code a cell with todays date upon creation but
not have it change each time the form is opened.

Thanks for the help,
Steve

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed on Date formulas shminas Excel Worksheet Functions 1 April 30th 06 11:05 AM
Date formula needed Rich Hayes Excel Worksheet Functions 4 December 9th 05 07:25 PM
Date formula needed VDan Excel Discussion (Misc queries) 4 August 31st 05 04:01 PM
Help needed with date format [email protected] Excel Discussion (Misc queries) 1 August 29th 05 09:11 AM
Date formulas needed David Excel Discussion (Misc queries) 9 July 24th 05 02:01 AM


All times are GMT +1. The time now is 03:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"