Automatic Date entry Help

ozstephan

Board Regular
Joined
Nov 19, 2005
Messages
52
Hi:
I have a s/s which I am developing. What I would like to do is have a cell where it is updated with todays date when someone makes a change to the row.

e.g. I want cell B3 to show the date that row 3 was last updated. e.g2 When I change cell G3, B3 will show the date it was updated.

Hope some out there can help. Thanks everyone
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I'm not sure if you can do this using a formula with iteration increased or not. Irregardless, I think I would just stick to using a VBA code solution. The example that you can download watches all cells in columns C to IV. This range is named. See the explanation in the code below...

ozstephan.zip

This code belongs in the worksheet class module that we are considering.
<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#008000">'name the range you will be watching for editing, "WatchForUpdatesRange"</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> Worksheet_Change(ByVal Target <font color="#0000A0">As</font> Range)
       <font color="#0000A0">If</font> <font color="#0000A0">Not</font> Intersect(Target, [WatchForUpdatesRange]) <font color="#0000A0">Is</font> <font color="#0000A0">Nothing</font> <font color="#0000A0">Then</font>
          <font color="#008000"> 'if the range that was just changed intersects the range refered to</font>
          <font color="#008000"> 'by the named range, "WatchForUpdatesRange", then call the following</font>
          <font color="#008000"> 'procedure</font>
           <font color="#0000A0">Call</font> SetEditTime(Target)
       <font color="#0000A0">End</font> <font color="#0000A0">If</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>


  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> SetEditTime(Target <font color="#0000A0">As</font> Range)
       <font color="#0000A0">On</font> <font color="#0000A0">Error</font> <font color="#0000A0">GoTo</font> Err_SetEditTime
       <font color="#0000A0">Dim</font> r <font color="#0000A0">As</font> Range

       Application.EnableEvents = <font color="#0000A0">False</font>
      <font color="#008000"> 'loop through the rows of the changed range</font>
       <font color="#0000A0">For</font> <font color="#0000A0">Each</font> r <font color="#0000A0">In</font> Target.Rows
          <font color="#008000"> 'place the current time in column B of the self-same row</font>
           Cells(r.Row, 2).Value = Now
          <font color="#008000"> 'if you only want the date, then format the cells in column b</font>
          <font color="#008000"> 'and or uncomment this line</font>
          <font color="#008000"> 'Cells(r.Row, 2).Value = Date</font>
       <font color="#0000A0">Next</font>

  Err_SetEditTime:
  Application.EnableEvents = <font color="#0000A0">True</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("91520061392984").value=document.all("91520061392984").value.replace(/<br \/>\s\s/g,"");document.all("91520061392984").value=document.all("91520061392984").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("91520061392984").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="91520061392984" wrap="virtual">
'name the range you will be watching for editing, "WatchForUpdatesRange"
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [WatchForUpdatesRange]) Is Nothing Then
'if the range that was just changed intersects the range refered to
'by the named range, "WatchForUpdatesRange", then call the following
'procedure
Call SetEditTime(Target)
End If
End Sub


Private Sub SetEditTime(Target As Range)
On Error GoTo Err_SetEditTime
Dim r As Range

Application.EnableEvents = False
'loop through the rows of the changed range
For Each r In Target.Rows
'place the current time in column B of the self-same row
Cells(r.Row, 2).Value = Now
'if you only want the date, then format the cells in column b
'and or uncomment this line
'Cells(r.Row, 2).Value = Date
Next

Err_SetEditTime:
Application.EnableEvents = True
End Sub</textarea>

ozstephan.zip
 
Upvote 0
something like;
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
if target.column=2 then exit sub
Cells(Target.Row, 2) = Date
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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