Automatic Date and Time

jblair626

New Member
Joined
Oct 17, 2011
Messages
18
I want the date and time to automatically populate when I enter something into cell C5
I want the Date to auto update in C6
and the time to auto update in C7 as soon as i enter something into C5
Is there a formula for this?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Welcome to the Board!

You can use a Change event:

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#007F00">'   Code goes in the Worksheet specific module</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#007F00">'   Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> rng = Target.Parent.Range("C5")<br>        <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>        <SPAN style="color:#007F00">'   Only look at that range</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Intersect(Target, rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>        <SPAN style="color:#007F00">'   Action if Condition(s) are met (do your thing here...)</SPAN><br>            <SPAN style="color:#00007F">With</SPAN> Target<br>                .Offset(1).Value = <SPAN style="color:#00007F">Date</SPAN><br>                .Offset(2).Value = Time<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0
I tried to copy and paste that to the work sheet after clicking veiw code. But when I enter values in cell c5, c6 and c7 do not change and a pop up appears that says end or debug I've tried both but cnnot figure it out.
Please help
 
Upvote 0
OK, so you copied it to the worksheet module, which is the right thing to do.

What error message do you get and what line of code is highlighted?

You can also try Debug->Compile from the VBE to check for the error. It may be as simple as a missing reference.
 
Upvote 0
It wasnt working because the sheet was protected and those 2 cells were locked. I unlocked them and now it works. Thank you
 
Upvote 0
Glad you got it sorted. If you don't want users to be able to edit C6:C7, then you can uprotect/protect the sheet programmatically:

ActiveSheet.Unprotect "Password"
' Code
ActiveSheet.Protect "Password"
 
Upvote 0
But when I close it and save it and open it back up. Everything on the code page goes away. How do I keep it there. Ive clicked the save icon multiple times.
 
Upvote 0
Try saving the workbook from Excel instead of the VBE.

If you're in Excel 2007+ you'll need to save it as a Macro Enabled workbook.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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