Basic Date/Time Macro Question

YDK

New Member
Joined
Jun 1, 2011
Messages
6
Morning all,

I have been tasked with amending an existing spreadsheet where a button click will enter the date/time into Column A.

I have been asked to separate the data so that the date is displayed in Column A and the Time in Column B, is this possible using one button?

If not possible could anyone help provide me with Macro details for separate date/time stamps?

It would mean using 2 buttons however if that's what it comes down to then so be it!

Bit of background the sheet is used to capture specific data relating to exactly when incoming calls are received, the agent who takes the call simply clicks the button to generate data.

Many thanks.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Code:
Sub DateAndTime()
    Range("A1") = DateValue(Now)
    Range("B1") = TimeValue(Now)
End Sub
 
Upvote 0
Code:
Sub DateAndTime()
    Range("A1") = DateValue(Now)
    Range("B1") = TimeValue(Now)
End Sub

Hi Sektor,

Thanks a lot for that, it appears to work however instead of overwriting the data in columns A and B with every new click I need new data to be displayed on subsequent rows every time the button is clicked.

Any ideas?
 
Upvote 0
Code:
Sub DateAndTime()
    Cells(Rows.Count, 1).End(xlUp)[COLOR="Red"][B].Offset(1,0)[/B][/COLOR] = DateValue(Now)
    Cells(Rows.Count, 2).End(xlUp)[COLOR="Red"][B].Offset(1,0)[/B][/COLOR] = TimeValue(Now)
End Sub
 
Last edited:
Upvote 0
Hmmm the values are still being written into A1 and B2 whenever I click the button :(
 
Upvote 0
Yep that's the tweak I made just before your post, excellent many, many thanks!
 
Upvote 0
Following on from the time/date macro, if I wanted to input a pre-populated value i.e. name in column E and team name in column F when clicking the button would this be the code;

Sub DateAndTime()
Cells(Rows.Count, "A").End(xlUp).Offset(1) = DateValue(Now)
Cells(Rows.Count, "B").End(xlUp).Offset(1) = TimeValue(Now)
Cells(Rows.Count, "E").End(xlUp).Offset(1) = Value(Smith, John)
Cells(Rows.Count, "F").End(xlUp).Offset(1) = Value(Technical Team)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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