Time Stamp when cell value is changed

SantanaKRE8s

Board Regular
Joined
Jul 11, 2023
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I have a VBA code to add a time stamp when ever the value of a cell is changed, but I am using a Count function in the cell, so I noticed the time stam is not working. Is there a way to make it work with the Function so that this is being modified automatically.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim MyDataRng As Range
Set MyDataRng = Range("C8:C13")

If Intersect(Target, MyDataRng) Is Nothing Then Exit Sub

On Error Resume Next
If Target.Offset(0, 1) = "" Then
Target.Offset(0, 1) = Now
End If

Target.Offset(0, 2) = Now

End Sub
 
You can only have one "Worksheet_Change" event procedure per sheet, so you have to combine them into one, like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'***BLOCK 1***
Dim rng As Range
Dim cell As Range

' See if any updates to column S
Set rng = Intersect(Range("X:X"), Target)

' What to do if update in column X
If Not rng Is Nothing Then

    ' Loop through values updated in column S
    Application.EnableEvents = False
    For Each cell In rng
        ' See if cell value is Resovled
        If cell.Value = "Resolved" Then
            ' Copy to bottom of resolved sheet
            Rows(cell.Row).Copy
            Sheets("Resolved").Range("A" & Sheets("Resolved").UsedRange.Rows.Count + 1).PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Application.CutCopyMode = False
            ' Remove from backlog sheet
            Rows(cell.Row).Delete
        End If
    Next cell
    Application.EnableEvents = True
End If

'***BLOCK 2***
' Update cell Z1 with any cell change
Application.EnableEvents = False
Range("Z1").Value = Now
Application.EnableEvents = True

End Sub
 
Upvote 1
Solution

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You can only have one "Worksheet_Change" event procedure per sheet, so you have to combine them into one, like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'***BLOCK 1***
Dim rng As Range
Dim cell As Range

' See if any updates to column S
Set rng = Intersect(Range("X:X"), Target)

' What to do if update in column X
If Not rng Is Nothing Then

    ' Loop through values updated in column S
    Application.EnableEvents = False
    For Each cell In rng
        ' See if cell value is Resovled
        If cell.Value = "Resolved" Then
            ' Copy to bottom of resolved sheet
            Rows(cell.Row).Copy
            Sheets("Resolved").Range("A" & Sheets("Resolved").UsedRange.Rows.Count + 1).PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Application.CutCopyMode = False
            ' Remove from backlog sheet
            Rows(cell.Row).Delete
        End If
    Next cell
    Application.EnableEvents = True
End If

'***BLOCK 2***
' Update cell Z1 with any cell change
Application.EnableEvents = False
Range("Z1").Value = Now
Application.EnableEvents = True

End Sub
Can this be set so it only shos the date and not the time?
 
Upvote 0
Can this be set so it only shos the date and not the time?
Sure. Just change this line:
VBA Code:
Range("Z1").Value = Now
to this:
VBA Code:
Range("Z1").Value = Date
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
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