Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Enter current time into cell hh:mm:ss


I am trying to create a macro that records the current time off th
clock on my computer. I am aware of the short cut (ctrl+shift+;).
However, this does not go into the actual seconds. Is there a way t
record the seconds as well

--
rglasuno
-----------------------------------------------------------------------
rglasunow's Profile: http://www.excelforum.com/member.php...nfo&userid=421
View this thread: http://www.excelforum.com/showthread.php?threadid=38213

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Enter current time into cell hh:mm:ss


Good evening rglasunow

You would be better off using the =NOW() function, the only problem
with this is that it will alter every time the sheet is recalculated.
The code below will call the NOW() function, format the cell
appropriately and then changes the cell contents from a formula to a
value.

Sub TimeStamp()
ActiveCell.FormulaR1C1 = "=NOW()"
With Selection
..NumberFormat = "h:mm:ss;@"
..Formula = .Value
End With
End Sub

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=382135

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Enter current time into cell hh:mm:ss


thanks man!! That worked perfect!!

--
rglasuno
-----------------------------------------------------------------------
rglasunow's Profile: http://www.excelforum.com/member.php...nfo&userid=421
View this thread: http://www.excelforum.com/showthread.php?threadid=38213

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Enter current time into cell hh:mm:ss


Hi rglasunow

Glad to help. Appreciate the feedback.

Dominic

--
dominic
-----------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...fo&userid=1893
View this thread: http://www.excelforum.com/showthread.php?threadid=38213

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Enter current time into cell hh:mm:ss

Why not do it in one go?

Sub TimeStamp()
ActiveCell.Value = Format(Time,"h:mm:ss;@")
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"dominicb" wrote in
message ...

Good evening rglasunow

You would be better off using the =NOW() function, the only problem
with this is that it will alter every time the sheet is recalculated.
The code below will call the NOW() function, format the cell
appropriately and then changes the cell contents from a formula to a
value.

Sub TimeStamp()
ActiveCell.FormulaR1C1 = "=NOW()"
With Selection
NumberFormat = "h:mm:ss;@"
Formula = .Value
End With
End Sub

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile:

http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=382135





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Enter current time into cell hh:mm:ss

One way:

Public Sub InsertTime()
With ActiveCell
.Value = Time
.NumberFormat = "hh:mm:ss"
End With
End Sub


In article ,
rglasunow
wrote:

I am trying to create a macro that records the current time off the
clock on my computer. I am aware of the short cut (ctrl+shift+;).
However, this does not go into the actual seconds. Is there a way to
record the seconds as well?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Enter current time into cell hh:mm:ss

This really doesn't do exactly what the OP says s/he wanted - since
NOW() returns both the date and the time (though it may be acceptable to
the OP).

Entering the time using Activecell, but then using Selection for

.Formula = .Value

is dangerous - if the user has selected multiple cells, it will reformat
and wipe out any formulae in that selection. Far better to stick with
ActiveCell.

Also, if the OP want's both date and time, there's no need to use XL's
NOW() function, use VBA's Now method instead:

Public Sub TimeStamp()
With ActiveCell
.Value = Now
.NumberFormat = "h:mm:ss"
End With
End Sub


In article ,
dominicb
wrote:

Good evening rglasunow

You would be better off using the =NOW() function, the only problem
with this is that it will alter every time the sheet is recalculated.
The code below will call the NOW() function, format the cell
appropriately and then changes the cell contents from a formula to a
value.

Sub TimeStamp()
ActiveCell.FormulaR1C1 = "=NOW()"
With Selection
.NumberFormat = "h:mm:ss;@"
.Formula = .Value
End With
End Sub

HTH

DominicB

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Enter current time into cell hh:mm:ss

Better:

Public Sub InsertTime()
With ActiveCell
.NumberFormat = "hh:mm:ss"
.Value = Time
End With
End Sub

In article ,
JE McGimpsey wrote:

Public Sub InsertTime()
With ActiveCell
.Value = Time
.NumberFormat = "hh:mm:ss"
End With
End Sub

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
When I hit enter, why is the current cell highlighted? Mana Excel Discussion (Misc queries) 1 September 29th 08 11:36 PM
Enter text automatically based on current time jmj713 Excel Discussion (Misc queries) 3 September 7th 07 04:18 PM
Can I automatically enter the current date or current time into a Ben New Users to Excel 7 October 19th 05 03:38 PM
enter a current date in a cell? Tpeyton77 Excel Discussion (Misc queries) 2 June 8th 05 02:30 AM
How to enter current static time in Excel in 00:00:00.0 format? Wlumkong Excel Worksheet Functions 3 May 12th 05 03:54 PM


All times are GMT +1. The time now is 10:05 PM.

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"

 

ExcelBanter Database Error
Database Error Database error
The ExcelBanter database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.excelbanter.com home page, then try to open another page.
  • Click the Back button to try another link.
The www.excelbanter.com forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.