Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
I'm working on a metrics log and I need to capture the current date and time in the same cell and for it to remain static. I found a code on this website but it only captures the time. I'm not familiar enough with this code to manipulate it for both date and time. Can someone provide the code to capture both date and time in the same cell? Thanks in advance....it's greatly appreciated. Laura |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi, Laura-
Will you please post your code? If you're capturing the system time and date and writing that value to a cell, it may be just a matter of formatting the cell to show both date and time. For instance: Dim Datestamp as Date Datestamp = Now() Range("A1").value = Datestamp In this example, if cell A1 is formatted properly, it will show both time and date. |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks Dave....
Here's the code: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column < 1 Then Exit Sub If Target.Row = 1 Then Exit Sub If IsEmpty(Target.Offset(0, 1)) Then Target.Offset(0, 1) = Date And Time Target.Offset(0, 1).NumberFormat = "m/dd/yy h:mm AM/PM" End If End Sub The cell is formated to date and time...here's what it looks like on the s/s: 1/00/00 12:00 AM I've played with the code a bit...but as you can see from the example above, it's now working. Thanks Laura "Dave O" wrote: Hi, Laura- Will you please post your code? If you're capturing the system time and date and writing that value to a cell, it may be just a matter of formatting the cell to show both date and time. For instance: Dim Datestamp as Date Datestamp = Now() Range("A1").value = Datestamp In this example, if cell A1 is formatted properly, it will show both time and date. |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Meant to say...it' not working.
"Laura" wrote: Thanks Dave.... Here's the code: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column < 1 Then Exit Sub If Target.Row = 1 Then Exit Sub If IsEmpty(Target.Offset(0, 1)) Then Target.Offset(0, 1) = Date And Time Target.Offset(0, 1).NumberFormat = "m/dd/yy h:mm AM/PM" End If End Sub The cell is formated to date and time...here's what it looks like on the s/s: 1/00/00 12:00 AM I've played with the code a bit...but as you can see from the example above, it's now working. Thanks Laura "Dave O" wrote: Hi, Laura- Will you please post your code? If you're capturing the system time and date and writing that value to a cell, it may be just a matter of formatting the cell to show both date and time. For instance: Dim Datestamp as Date Datestamp = Now() Range("A1").value = Datestamp In this example, if cell A1 is formatted properly, it will show both time and date. |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi, Laura-
Sorry for the delayed response: endless meetings droning on. Please try changing this line: Target.Offset(0, 1) = Date And Time ....to this, and let me know how it works: Target.Offset(0, 1).value = now() |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi Dave,
No Problem...totally understand about meetings... That didn't work...here's what the code looks like now: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column < 1 Then Exit Sub If Target.Row = 1 Then Exit Sub If IsEmpty(Target.Offset(0, 1)) Then Target.Offset(0, 1).Value = Now() Target.Offset(0, 1) = Time Target.Offset(0, 1).NumberFormat = "m/dd/yy h:mm AM/PM" End If End Sub It provides the time, but not the date: 1/00/00 2:02 PM Thanks...:) "Dave O" wrote: Hi, Laura- Sorry for the delayed response: endless meetings droning on. Please try changing this line: Target.Offset(0, 1) = Date And Time ....to this, and let me know how it works: Target.Offset(0, 1).value = now() |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
problem in date time picker size | Excel Discussion (Misc queries) | |||
Date time problem | Excel Discussion (Misc queries) | |||
Using VLOOKUP with a Date and Time | Excel Discussion (Misc queries) | |||
Date & Time problem | Excel Worksheet Functions | |||
Ugh..another time and date problem...HELP | Excel Worksheet Functions |