Multiple Worksheet_Change

sr7

New Member
Joined
Nov 16, 2021
Messages
5
HEllo, I am trying to build two timestamps in the same row that trigger from different cell changes.
When column B changes, timestamp in column F
When Column L changes, Timestamp in column M

My second timestamp wont work. any ideas? Heres my code:


VBA Code:
'timestamps

Private Sub Worksheet_Change(ByVal Target As Range)
Call EventChange_1(Target)
Call EventChange_2(Target)
End Sub


'assign timestamp

Sub EventChange_1(Target)
Dim F As Range, B As Range, t As Range

Set F = Range("F:F")
Set B = Range("B:B")
Set t = Target

If Intersect(t, B) Is Nothing Then Exit Sub

Application.EnableEvents = False
Range("F" & t.Row).Value = Now
Application.EnableEvents = True
End Sub

'Complete timestamp
Sub EventChange_2(Target)
Dim M As Range, L As Range, t As Range

Set M = Range("M:M")
Set L = Range("L:L")
Set t = Target

If Intersect(t, L) Is Nothing Then Exit Sub

Application.EnableEvents = False
Range("M" & t.Row).Value = Now
Application.EnableEvents = True
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Welcome to the Forum!

My second timestamp wont work. any ideas? Heres my code:

Your code "works" for me, in the sense that it behaves exactly as I'd expect.

Can you please provide more detail? When you say the code doesn't work, what cell changes are you making?
 
Upvote 0
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/16/2021  9:24:54 PM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

    Select Case Target.Column
        Case 2
            Target(, 5).Value = Now
        Case 12
            Target(, 2).Value = Now
    End Select
End Sub
 
Upvote 0
Welcome to the Forum!



Your code "works" for me, in the sense that it behaves exactly as I'd expect.

Can you please provide more detail? When you say the code doesn't work, what cell changes are you making?
Thanks for the Welcome and for looking at this. it seems to be working now!
Welcome to the Forum!



Your code "works" for me, in the sense that it behaves exactly as I'd expect.

Can you please provide more detail? When you say the code doesn't work, what cell changes are you making?
 
Upvote 0
it seems to be working now!
That's good to hear, thanks.

@My Aswer Is This has provided more succinct code you also might like to try. At the moment, it's set up to deal with only cell changing at a time, but this can easily be changed to more than one row/column if you envisage the user changing multiple cells at once and you want to time-stamp all relevant cells?
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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