#1   Report Post  
Member
 
Posts: 84
Default Auto Date & Time

Hey all,

I have this code (which I got from this forum... thank you!) in a worksheet but I need a format code as well.


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A" & Target.Row).Value = Date & Time
Application.EnableEvents = True
End Sub


Excel is returning this format:

11/21/20089:10:55 AM (This is correct except it's formatted wrong)

I've tried formating the cells to: m/d/yy h:mm but I still get the above format. The only thing I can conclude is that I must have a format command in the code as well.

Please help!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Auto Date & Time

Hello

Try this:

Range("A" & Target.Row).Value = Format(Date & " " & Time, "m/d/yy h:mm")

Regards,
Per

"Keyrookie" skrev i meddelelsen
...

Hey all,

I have this code (which I got from this forum... thank you!) in a
worksheet but I need a format code as well.


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A" & Target.Row).Value = Date & Time
Application.EnableEvents = True
End Sub


Excel is returning this format:

11/21/20089:10:55 AM (This is correct except it's formatted wrong)

I've tried formating the cells to: m/d/yy h:mm but I still get the
above format. The only thing I can conclude is that I must have a
format command in the code as well.

Please help!




--
Keyrookie


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Auto Date & Time

You are assigning...

Date & Time

in the 2nd line of the subroutine. This butts up the date next to the time
with nothing between them... Excel won't see that as a date/time
combination. You need a space between them. Try assigning this instead...

Date & " " & Time

I think you will then be able to format the cell any way that you want.

--
Rick (MVP - Excel)


"Keyrookie" wrote in message
...

Hey all,

I have this code (which I got from this forum... thank you!) in a
worksheet but I need a format code as well.


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A" & Target.Row).Value = Date & Time
Application.EnableEvents = True
End Sub


Excel is returning this format:

11/21/20089:10:55 AM (This is correct except it's formatted wrong)

I've tried formating the cells to: m/d/yy h:mm but I still get the
above format. The only thing I can conclude is that I must have a
format command in the code as well.

Please help!




--
Keyrookie


  #4   Report Post  
Member
 
Posts: 84
Default

Thanks Per, that did the trick! Also, for anyone else looking for this result, cells must be custom formatted to "m/d/yy h:mm AM/PM" otherwise Execl will return military time.

Thanks again for the quick response,

K


Quote:
Originally Posted by Per Jessen View Post
Hello

Try this:

Range("A" & Target.Row).Value = Format(Date & " " & Time, "m/d/yy h:mm")

Regards,
Per

"Keyrookie" skrev i meddelelsen
...

Hey all,

I have this code (which I got from this forum... thank you!) in a
worksheet but I need a format code as well.


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A" & Target.Row).Value = Date & Time
Application.EnableEvents = True
End Sub


Excel is returning this format:

11/21/20089:10:55 AM (This is correct except it's formatted wrong)

I've tried formating the cells to: m/d/yy h:mm but I still get the
above format. The only thing I can conclude is that I must have a
format command in the code as well.

Please help!




--
Keyrookie
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 with auto update of date and time saran Excel Worksheet Functions 1 June 28th 08 02:27 AM
auto update of date and time whenever changes are made to a xcel s saran Excel Worksheet Functions 9 June 23rd 08 02:44 PM
how do i auto insert a date and time stamp cjensen Excel Discussion (Misc queries) 3 February 6th 07 03:44 AM
Auto insert Date & Time when another cell is populated Trixie Excel Discussion (Misc queries) 1 October 2nd 06 03:59 AM
Auto insert date/time Tino Excel Worksheet Functions 1 September 8th 06 05:58 PM


All times are GMT +1. The time now is 01:59 AM.

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

About Us

"It's about Microsoft Excel"