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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
L

Legacy 98055

Guest
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
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
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
 

Watch MrExcel Video

Forum statistics

Threads
1,114,380
Messages
5,547,599
Members
410,802
Latest member
DataMgmtAnalyst7
Top