Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 77
Default Static Date and Time code problem

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Static Date and Time code problem

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 77
Default Static Date and Time code problem

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 77
Default Static Date and Time code problem

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Static Date and Time code problem

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 77
Default Static Date and Time code problem

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
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
problem in date time picker size sjayar Excel Discussion (Misc queries) 3 November 11th 05 05:12 PM
Date time problem FSt1 Excel Discussion (Misc queries) 1 September 26th 05 03:35 PM
Using VLOOKUP with a Date and Time Charles Excel Discussion (Misc queries) 4 September 20th 05 06:38 PM
Date & Time problem ckiraly Excel Worksheet Functions 2 August 15th 05 01:13 PM
Ugh..another time and date problem...HELP Sandy Excel Worksheet Functions 4 July 29th 05 05:37 PM


All times are GMT +1. The time now is 03:04 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"