laurens102
New Member
- Joined
- Dec 7, 2023
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hello I am trying to combine two worksheet changes that will update separate timestamps based on if their corresponding columns have been changed. The problem I am having is only one timestamp is changed while the other on stays the same.
Private Sub Worksheet_Change1(ByVal Target As Range)
'Update 20140722
Dim WorkRng1 As Range1
Dim Rng1 As Range1
Dim xOffsetColumn As Integer
Set WorkRng1 = Intersect(Application.ActiveSheet.Range1("B:B"), Target)
xOffsetColumn = 3
If Not WorkRng1 Is Nothing Then
Application.EnableEvents = False
For Each Rng1 In WorkRng1
If Not VBA.IsEmpty(Rng1.Value) Then
Rng1.Offset(0, xOffsetColumn).Value = Now
Rng1.Offset(0, xOffsetColumn).NumberFormat = "mm/dd/yyyy, hh:mm:ss"
Else
Rng1.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
Private Sub Worksheet_Change2(ByVal Target As Range)
'Update 20140722
Dim WorkRng2 As Range2
Dim Rng2 As Range2
Dim xOffsetColumn As Integer
Set WorkRng2 = Intersect(Application.ActiveSheet.Range2("G:G"), Target)
xOffsetColumn = 3
If Not WorkRng2 Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng2
If Not VBA.IsEmpty(Rng2.Value) Then
Rng2.Offset(0, xOffsetColumn).Value = Now
Rng2.Offset(0, xOffsetColumn).NumberFormat = "mm/dd/yyyy, hh:mm:ss"
Else
Rng2.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_Change1(ByVal Target As Range)
'Update 20140722
Dim WorkRng1 As Range1
Dim Rng1 As Range1
Dim xOffsetColumn As Integer
Set WorkRng1 = Intersect(Application.ActiveSheet.Range1("B:B"), Target)
xOffsetColumn = 3
If Not WorkRng1 Is Nothing Then
Application.EnableEvents = False
For Each Rng1 In WorkRng1
If Not VBA.IsEmpty(Rng1.Value) Then
Rng1.Offset(0, xOffsetColumn).Value = Now
Rng1.Offset(0, xOffsetColumn).NumberFormat = "mm/dd/yyyy, hh:mm:ss"
Else
Rng1.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
Private Sub Worksheet_Change2(ByVal Target As Range)
'Update 20140722
Dim WorkRng2 As Range2
Dim Rng2 As Range2
Dim xOffsetColumn As Integer
Set WorkRng2 = Intersect(Application.ActiveSheet.Range2("G:G"), Target)
xOffsetColumn = 3
If Not WorkRng2 Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng2
If Not VBA.IsEmpty(Rng2.Value) Then
Rng2.Offset(0, xOffsetColumn).Value = Now
Rng2.Offset(0, xOffsetColumn).NumberFormat = "mm/dd/yyyy, hh:mm:ss"
Else
Rng2.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub