Set date and time in cells

PaulS

Board Regular
Joined
Feb 26, 2006
Messages
66
The function of a macro is:
Enter the current date in cell Ax (any cell on row x may be selected),
and enter the current time in cell Bx.
I have the following lines in the macro for filling the time:
Dim c As Range
' cell selected as variable
Set c = Selection
c = Hour(Now()) & ":" & Minute(Now())
' copy value of c also into cell H3
H3 = c
End Sub
My knowledge of macros is very limited; can you advise a good book?
Thanks
Paul
 

PaulS

Board Regular
Joined
Feb 26, 2006
Messages
66
Thanks, this is very easy, but not enough.
I tried the following, but this will give errors. What is wrong?

Dim c As Range

' cell selected as variable
Set c = Selection
Range(Cells("A", c.Row)) = Today()
Range(Cells("B", c.Row)) = Hour(Now()) & ":" & Minute(Now())

' copy value of c also into cell H2 and H3 = header
Range(Cells("H2")) = Range(Cells("A", c.Row))
Range(Cells("H3")) = Range(Cells("B", c.Row))

End Sub

Thanks,
Paul
 

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Hi,

How about;

Code:
' cell selected as variable
Set c = Selection
Range("A" & c.Row) = Date
Range("B" & c.Row) = Format(Time, "hh:mm")

' copy value of c also into cell H2 and H3 = header
Range("H2") = Range("A" & c.Row)
Range("H3") = Range("B" & c.Row)
 

Forum statistics

Threads
1,082,438
Messages
5,365,531
Members
400,837
Latest member
ELMST616

Some videos you may like

This Week's Hot Topics

Top