GerMae
New Member
- Joined
- Apr 30, 2022
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello, I've spent hours trying to get this to work and I keep finding similar issues, but not my exact one. I have a worksheet that I am tracking an inventory count in and I would like the timestamp to update automatically when the count changes basically to represent an "effective date" of the new count.
Worksheet Setup
I'm current using the below VBA BUT it keeps erroring out at Application.Undo
Sub Worksheet_Change(ByVal Target As Range)
Dim myCount As Range
Dim myEffTime As Range
Dim myUpdtdTime As Range
Set myCount = Range("A3:A4")
For Each cell In myCount
Dim OldValue As Variant
'Application.EnableEvents = False
Application.Undo
OldValue = cell.Value
Application.Undo
Application.EnableEvents = True
If OldValue <> cell.Value Then
Set myEffTime = Range("B3")
Set myUpdtdTime = Range("B4")
If myEffTime.Value = "" Then
myEffTime.Value = Now
End If
myUpdtdTime.Value = Now
End If
Next cell
End Sub
Worksheet Setup
- There is a starting count in A1 (entered manually)
- A2 has a formula that counts the X's from another worksheet (used inventory)
- A3 has a formula A1-A2
I'm current using the below VBA BUT it keeps erroring out at Application.Undo
Sub Worksheet_Change(ByVal Target As Range)
Dim myCount As Range
Dim myEffTime As Range
Dim myUpdtdTime As Range
Set myCount = Range("A3:A4")
For Each cell In myCount
Dim OldValue As Variant
'Application.EnableEvents = False
Application.Undo
OldValue = cell.Value
Application.Undo
Application.EnableEvents = True
If OldValue <> cell.Value Then
Set myEffTime = Range("B3")
Set myUpdtdTime = Range("B4")
If myEffTime.Value = "" Then
myEffTime.Value = Now
End If
myUpdtdTime.Value = Now
End If
Next cell
End Sub