Using VBA to Record a Date Stamp

Edd_de Spretter

New Member
Joined
Jul 4, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

Any help would be greatly received, I am currently using the below VBA to automatically record a date stamp when amending text in cells A1 to A10.

Does anyone know how I would adapt the code to function for data in more than one cell, for example to record a date stamp when I alter text in A1 to A10 and B1 to B10.

This is the code I am currently using:

Code.JPG


Thanks in advance.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this:
VBA Code:
Set MyDataRng = Union(Range("A2:A10"),Range("B2:B10"))
 
Upvote 0
I'm confused about exactly what range you want to include in the range that will trigger a date stamp when manual changes are made to any of its cells. The code below will trigger a date stamp if any cell or cells are changed in A1:A10. This will place a date stamp in any empty companion cell or cells in column B.

If you can elaborate on where you want date stamps to appear if the trigger range is changed to A1:B10, the code can be modified accordingly.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, myDataRange As Range
Set myDataRange = Range("A1:A10")
If Not Intersect(myDataRange, Target) Is Nothing Then
    For Each c In Intersect(myDataRange, Target)
        If c.Offset(0, 1) = "" Then c.Offset(0, 1).Value = Now()
    Next c
End If
End Sub
 
Upvote 0
I'm confused about exactly what range you want to include in the range that will trigger a date stamp when manual changes are made to any of its cells. The code below will trigger a date stamp if any cell or cells are changed in A1:A10. This will place a date stamp in any empty companion cell or cells in column B.

If you can elaborate on where you want date stamps to appear if the trigger range is changed to A1:B10, the code can be modified accordingly.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, myDataRange As Range
Set myDataRange = Range("A1:A10")
If Not Intersect(myDataRange, Target) Is Nothing Then
    For Each c In Intersect(myDataRange, Target)
        If c.Offset(0, 1) = "" Then c.Offset(0, 1).Value = Now()
    Next c
End If
End Sub
Hi Joe,

Thank you for your reply.

Essentially in my spreadsheet if initials are added to cells in Column A I want the time stamp to record in the cells of column C.

If subsequently cells in column B are updated I want the time stamp to record in the cells of column D.

Thank you,
 
Upvote 0
Hi Joe,

Thank you for your reply.

Essentially in my spreadsheet if initials are added to cells in Column A I want the time stamp to record in the cells of column C.

If subsequently cells in column B are updated I want the time stamp to record in the cells of column D.

Thank you,
I've assumed if the date stamp cell is not empty you don't want to overwrite it. If that's not what you want, just remove this bit "If c.Offset(0, 2) = "" Then" from the line just above the Next c line.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, myDataRange As Range
Set myDataRange = Range("A1:B10")
If Not Intersect(myDataRange, Target) Is Nothing Then
    For Each c In Intersect(myDataRange, Target)
        If c.Offset(0, 2) = "" Then c.Offset(0, 2).Value = Now()
    Next c
End If
End Sub
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range) Dim c As Range, myDataRange As Range Set myDataRange = Range("A1:B10") If Not Intersect(myDataRange, Target) Is Nothing Then For Each c In Intersect(myDataRange, Target) If c.Offset(0, 2) = "" Then c.Offset(0, 2).Value = Now() Next c End If End Sub
That works perfectly, thank you very much for your assistance.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,951
Members
449,095
Latest member
nmaske

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