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
|