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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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
 
Upvote 0
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)
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top