Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Seo Services company Manchester

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-24-2005, 06:26 PM
rglasunow rglasunow is offline
Registered User
 
Join Date: 24 Dec 2003
Posts: 15
rglasunow is becoming part of the community
Enter current time into cell hh:mm:ss

Please Register to Remove these Ads

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?
Reply With Quote
  #2  
Old 06-24-2005, 06:40 PM
dominicb's Avatar
dominicb dominicb is online now
Forum Moderator
 
Join Date: 25 Jan 2005
Location: Lancashire, England
MS Office Version:MS Office 2000, 2003 & 2007
Posts: 3,561
dominicb is very confident of their ability dominicb is very confident of their ability dominicb is very confident of their ability
Smile

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
Reply With Quote
  #3  
Old 06-24-2005, 06:45 PM
rglasunow rglasunow is offline
Registered User
 
Join Date: 24 Dec 2003
Posts: 15
rglasunow is becoming part of the community
thanks man!! That worked perfect!!!
Reply With Quote
  #4  
Old 06-24-2005, 07:12 PM
dominicb's Avatar
dominicb dominicb is online now
Forum Moderator
 
Join Date: 25 Jan 2005
Location: Lancashire, England
MS Office Version:MS Office 2000, 2003 & 2007
Posts: 3,561
dominicb is very confident of their ability dominicb is very confident of their ability dominicb is very confident of their ability
Smile

Hi rglasunow

Glad to help. Appreciate the feedback.

DominicB
Reply With Quote
  #5  
Old 06-24-2005, 08:05 PM
Bob Phillips
Guest
 
Posts: n/a
Re: 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" <dominicb.1r5l6e_1119654307.1749@excelforum-nospam.com> wrote in
message news:dominicb.1r5l6e_1119654307.1749@excelforum-nospam.com...
>
> 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
>



Reply With Quote
  #6  
Old 06-24-2005, 08:05 PM
JE McGimpsey
Guest
 
Posts: n/a
Re: 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.1r5l6c_1119654306.1858@excelforum-nospam.com>,
rglasunow <rglasunow.1r5l6c_1119654306.1858@excelforum-nospam.com>
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?

Reply With Quote
  #7  
Old 06-24-2005, 08:05 PM
JE McGimpsey
Guest
 
Posts: n/a
Re: 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.1r5l6e_1119654307.1749@excelforum-nospam.com>,
dominicb <dominicb.1r5l6e_1119654307.1749@excelforum-nospam.com>
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

Reply With Quote
  #8  
Old 06-24-2005, 08:05 PM
JE McGimpsey
Guest
 
Posts: n/a
Re: 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 <jemcgimpsey-41B6C2.17395424062005@msnews.microsoft.com>,
JE McGimpsey <jemcgimpsey@mvps.org> wrote:

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

Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Forum Jump